/**
 * Created by json on 2016/9/28.
 */
var US_NULL     =   0;
var US_READY    =   1;
var US_PLAY     =   2;
$.record_seconds = 0;
$.OnOverRecordObj = null;
$.OnOverRecord=function(seconds,url){
    cc.log("jsUrl==",url);
    if (cc.sys.os == cc.sys.OS_ANDROID) {
        seconds = parseInt(seconds);
        seconds = Math.ceil(seconds/1000);
    }
    if(seconds == 0)
    {
        seconds = $.record_seconds ;
    }
    if(seconds > 1)
    {
        seconds = Math.ceil(seconds- 1);
        if($.OnOverRecordObj){
            $.OnOverRecordObj.SendVoice(seconds,url);
        }else{
            csmj.MJ_Data.SendVoice(seconds,url);
        }
    }
}
csmj.mj_uiGameScene = cc.Scene.extend({
    sprite:null,
    m_nRound : 1,
    m_nMaxRound : 1,
    m_byYuPai : 88,
    m_nLeftTime : 8,


    m_bIsHandMjEnabled : false,

    m_vecFourOutCard:[],
    m_vecOutCard : [],
    m_vecHandCard : [],
    m_vecChiCard : [],

    m_vecGuiPai : [],
    m_byTing : [],
    m_vecChiSide : [],
    m_byHuIndex : [],
    m_vecRoundWinScore : [],
    m_sGameName : "",
    m_nStartRecordTime : 0,
    timeOut:false,
    ctor:function () {
        this._super();
        $.OnOverRecordObj = csmj.MJ_Data;
        csmj.MJ_Data.m_uiGameLayer = this;

        $.is_FirstLogin = false;

        this.m_chiXuanSeq =[];//[3];
        this.m_gangXuanSeq=[];//[4];
        this.m_vecXuanArrow=[] ;//[2];
        this.m_vecVoiceSeq=[];

        this.m_nRound = 1;
        this.m_nMaxRound = 24;
        this.m_byYuPai = 1;
        this.m_nLeftTime = 1;
        this.m_byTing = [0,0,0,0];
        this.m_vecRoundWinScore = [0,0,0,0];

        this.m_bGameStarted = false;

        this.vecUser = [null,null,null,null];

        this.m_vecGuiPai = [];

        this.mChairID = 0;

        mj4.MajLogic.Init();


        this.mainNode=ccs.load("res/ZJMJ_GameScene.json").node;
        this.addChild(this.mainNode);


        this.initMain(this.mainNode);
        this.initMusic(this.mainNode);
        this.initChatView(this.mainNode);

        //获取网络状态和电量
        this.schedule(this.OnReloadWifiAndPower,1);

        this.InitTable();
        this.renew_dnxb();
        this._checkLeftTime();
        this.schedule(this.checkHandMj,3);
        this.schedule(this._checkLeftTime,1.0);
        this.schedule(this._checkVoice,0.2);

        //test////////////////////////////
        //test end////////////////////////////
        //csmj.MJ_Data.InitData();

        var tanpai =  [[8,18,19,21,23,25,26,255,255,255,255,255,255,255],[255,3,22,6,20,0,255,0,255],
            [2,4,5,10,10,12,17,19,21,23,24,24,26,255],[255,0,255,0,255,0,255,0,255],
            [0,1,3,7,8,10,11,11,15,17,18,25,25,255],[255,0,255,0,255,0,255,0,255],
            [0,2,6,6,9,9,9,14,16,17,19,25,26,255],[255,0,255,0,255,0,255,0,255]];
        //this.showTanPai(tanpai);

        cc.audioEngine.playEffect("res/mj4/sound/join_room.wav",false);

        this.schedule(this._checkNetwork,1.0);
    },
    _checkNetwork : function()
    {
        if(dwc.DT_Data_Login.isConnected() == false)
        {
            this.unschedule(this._checkNetwork);

            var alert=new dwc.PopupAlert("网络连接已中断，重新登录可继续游戏",function()
            {
                cc.director.runScene(new dwc.LoginScene());
            });
            this.addChild(alert);
            alert.Show();
        }
    },
    initMusic : function(mainNode)
    {
        var that = this;


        this.effectBtn=$.getNodeByName(mainNode,"ID_CHECKBOX_EFFECT");
        this.effectBtn.addEventListener(function (sender,type) {
            if(!that.effectBtn.isSelected())
            {
                that.effectBtn.setSelected(false);
                cc.audioEngine.setEffectsVolume(0.0);
            }else{
                that.effectBtn.setSelected(true);
                cc.audioEngine.setEffectsVolume(0.8);
            }
        });

        this.musicBtn=$.getNodeByName(mainNode,"ID_CHECKBOX_MUSIC");
        this.musicBtn.addEventListener(function (sender,type) {
            if(!that.musicBtn.isSelected())
            {
                that.musicBtn.setSelected(false);
                cc.audioEngine.setMusicVolume(0.0);
            }else{
                that.musicBtn.setSelected(true);
                cc.audioEngine.setMusicVolume(0.8);
            }
        });
    },
    GetMajSide : function(bySeatID)
    {
        if(bySeatID < 4)
        {
            return mj4.MajLogic.GetMajSide(bySeatID);
        }else{
            return null;
        }

    },
    _checkDismiss : function()
    {
        var that = this;
        if(that.cntDismissWaitTimer > 0)
        {
            that.cntDismissWaitTimer--;
            that.dismissWaitTimerLabel.setString("" + that.cntDismissWaitTimer);
            if(that.cntDismissWaitTimer==0)
            {
                csmj.MJ_Data.SendDismissRoom();
            }
        }
    },
    checkHandMj : function()
    {
        var that = this;
        if(this.m_bGameStarted)
        {
            var lMajSide = that.GetMajSide(0);

            if(lMajSide && lMajSide.GetHandMjCount() % 3 == 2)
            {
                if (this.m_byTing[0]  == 0)
                {
                    that.enableHandMj(true);
                }else{
                    that.enableHandMj(false);
                }
            }else{
                that.enableHandMj(false);
            }
        }else{
            that.enableHandMj(false);
        }
    },
    _checkVoice : function()
    {
        if(this.playVoiceLeftSeconds == undefined)
        {
            this.playVoiceLeftSeconds = 0;
        }
        if(this.m_vecVoiceSeq && this.m_vecVoiceSeq.length > 0)
        {
            if(this.playVoiceLeftSeconds <= 0)
            {

                var vecArg = this.m_vecVoiceSeq.shift();
                var uid = vecArg[0];
                var seat = vecArg[1];
                var seconds = vecArg[2];
                var url = vecArg[3];
                this.playVoiceLeftSeconds = seconds + 0.5;

                this.viewSeat=this.SwitchViewChairID(seat);
                if(this.viewSeat){
                    this.userList[this.viewSeat].luYinSprite.setVisible(true);
                }
                this.OnPlayVoice(seconds,url);
            }
        }
        if(this.playVoiceLeftSeconds > 0)
        {
            var oldSeconds = this.playVoiceLeftSeconds;
            this.playVoiceLeftSeconds = this.playVoiceLeftSeconds - 0.2;
            if(oldSeconds > 0 && this.playVoiceLeftSeconds <= 0)
            {
                this.userList[this.viewSeat].luYinSprite.setVisible(false);
            }
        }
    },
    initMain: function (mainNode) {
        var that=this;
        //test
        //this.schedule(that.OnTest,3,40,2);
        this.num=-1;
        this.index=0;

        this.spBG = $.getNodeByName(mainNode,"ID_LAYOUT_BGMASK");
        this.nodeMyHandMj = $.getNodeByName(mainNode,"ID_NODE_MYHANDMJ");
        this.nodeJieSuan = $.getNodeByName(mainNode,"ID_NODE_JIESUAN");
        this.nodeJieSuanBG = $.getNodeByName(mainNode,"ID_NODE_JIESUANBG");

        csmj.JieSuanReportDialog.init(mainNode);

        this.spLogo = $.getNodeByName(mainNode,"ID_SPRITE_LOGO");


        this.fjhLabel = $.getNodeByName(mainNode,"ID_LABEL_FJH");
        this.leftpaiLabel = $.getNodeByName(mainNode,"ID_LABEL_LEFTPAI");
        this.lefttimeLabel = $.getNodeByName(mainNode,"ID_LABEL_LEFTTIME");
        //电量 wifi
        this.powerBar= $.getNodeByName(mainNode,"ID_LOADINGBAR_POWERBAR");
        this.netSprite= $.getNodeByName(mainNode,"ID_SPRITE_WANGLUO");

        this.roundLabel = $.getNodeByName(mainNode,"ID_LABEL_ROUND");
        //话筒背景
        this.voiceBack=$.getNodeByName(mainNode,"ID_IMAGE_HUADONGBG");
        this.volumeSprite=$.getNodeByName(mainNode,"ID_SPRITE_YINJIE");
        this.voiceBack.setVisible(false);

        var spGuiPai0=$.getNodeByName(mainNode,"ID_SPRITE_GUIPAI0");
        var spGuiPai1=$.getNodeByName(mainNode,"ID_SPRITE_GUIPAI1");

        //spGuiPai1.setVisible(false);
        //spGuiPai2.setVisible(false);

        //提示
        this.hintBack=$.getNodeByName(mainNode,"ID_SPRITE_HINT_MSG");
        this.hintBack.setVisible(false);
        this.hintLabel=$.getNodeByName(mainNode,"ID_LABEL_HINTLABEL");

        this.settingBtn = $.getNodeByName(mainNode,"ID_BUTTON_SETTING");
        this.settingBtn.addClickEventListener(function () {
            that.settingLayout.setVisible(true);
        });
        this.chatBtn = $.getNodeByName(mainNode,"ID_BUTTON_CHAT");
        this.chatBtn.addClickEventListener(function () {
            //that.chatBack.setVisible(true);
            var chat=this.chatView=new dwc.GameChat(that.chatEmotionBtnClick.bind(that),that.chatYuYinBtnClick.bind(that),this.chatTextMsg.bind(that));
            this.addChild(chat);
            chat.Show(false);
        }.bind(this));

        this.voiceBtn = $.getNodeByName(mainNode,"ID_BUTTON_VOICE");
        this.voiceBtn.addTouchEventListener(function (a,b) {
            that.OnVoiceBtnClick(a,b);
        },this);




        this.currentSprite=new cc.Sprite("res/mj4/outmjtile_sign.png");//new cc.Sprite("#outmjtile_sign.png");
        this.currentSprite.setAnchorPoint(0.5,0.5);
        this.currentSprite.setPosition(0,0);
        this.currentSprite.setVisible(false);
        this.spBG.addChild(this.currentSprite,100);

        this.currentSprite.runAction(cc.sequence(cc.moveBy(0.6,cc.p(0,15)),
            cc.moveBy(0.6,cc.p(0,-15))).repeatForever());
        //检测是否是长按
        this.schedule(this.OnLongPressed, 0.1);

        this.inviteBtn = $.getNodeByName(mainNode,"ID_BUTTON_INVITE");
        this.inviteBtn.addClickEventListener(function () {
            that.OnInvite();
            //that.showOperatorBar(true,false,false,false,true,true);
        });

        this.backLayout = $.getNodeByName(mainNode,"ID_LAYOUT_BACK");
        this.backOK = $.getNodeByName(mainNode,"ID_LAYOUT_BACK_OK");
        this.backCancel = $.getNodeByName(mainNode,"ID_LAYOUT_BACK_CANCEL");
        this.backOK.addClickEventListener(function () {
            that.backLayout.setVisible(false);
            csmj.MJ_Data.SendLeave();
            cc.director.runScene(new dwc.DT_MainScene());
        });

        this.backCancel.addClickEventListener(function () {
            that.backLayout.setVisible(false);
        });

        this.dismissWaitLayout = $.getNodeByName(mainNode,"ID_LAYOUT_DISMISS_WAIT");
        this.dismissWaitClose = $.getNodeByName(mainNode,"ID_BUTTON_DISMISS_WAIT_CLOSE");
        this.dismissWaitTimerLabel = $.getNodeByName(mainNode,"ID_LABEL_DISMISSWAIT_TIMER");
        this.dismissWaitClose.addClickEventListener(function () {
            that.dismissWaitLayout.setVisible(false);
        });
        this.dismissWaitLayout.setVisible(false);

        this.dismissLayout = $.getNodeByName(mainNode,"ID_LAYOUT_DISMISS");
        this.dismissOK = $.getNodeByName(mainNode,"ID_BUTTON_DISMISS_OK");


        this.dismissCancel = $.getNodeByName(mainNode,"ID_BUTTON_DISMISS_CANCEL");

        this.dismissOK.addClickEventListener(function () {
            csmj.MJ_Data.SendDismissRoom();
            //that.dismissLayout.setVisible(false);
            //that.dismissWaitLayout.setVisible(true);
        });
        this.dismissCancel.addClickEventListener(function () {
            that.dismissLayout.setVisible(false);
        });

        this.suredismissLayout = $.getNodeByName(mainNode,"ID_LAYOUT_SUREDISMISS");
        this.suredismissAgree = $.getNodeByName(mainNode,"ID_BUTTON_SUREDISMISS_AGREE");
        this.suredismissRefuse = $.getNodeByName(mainNode,"ID_BUTTON_SUREDISMISS_REFUSE");

        this.suredismissAgree.addClickEventListener(function () {
            that.suredismissLayout.setVisible(false);
            csmj.MJ_Data.SendAgreeDismissRoom();
        });
        this.suredismissRefuse.addClickEventListener(function () {
            that.suredismissLayout.setVisible(false);
            csmj.MJ_Data.SendRefuseDismissRoom();
        });


        this.settingLayout = $.getNodeByName(mainNode,"ID_LAYOUT_SETTING");
        this.settingClose = $.getNodeByName(mainNode,"ID_BUTTON_SETTING_CLOSE");
        //this.settingBack = $.getNodeByName(mainNode,"ID_BUTTON_SETTING_BACK");
        this.settingDismiss = $.getNodeByName(mainNode,"ID_BUTTON_SETTING_DISMISS");

        //this.settingBack.addClickEventListener(function () {
            //that.settingDismiss.setVisible(false);
        //});
        this.settingDismiss.addClickEventListener(function () {
            that.settingLayout.setVisible(false);

            var cntUser = 0;
            for(var i = 0;i<4;i++)
            {
                if(that.vecUser && that.vecUser[i].uid > 0)
                {
                    cntUser++;
                }
            }
            csmj.MJ_Data.SendTryDismissRoom();
            if(cntUser > 1)
            {
                that.dismissWaitLayout.setVisible(true);
                that.cntDismissWaitTimer = 60;
                that.unschedule(that._checkDismiss);
                that.schedule(that._checkDismiss, 1.0);
            }
            //cc.audioEngine.stopAllEffects();
            //cc.director.runScene(new dwc.DT_MainScene());
        });

        this.settingClose.addClickEventListener(function () {
            that.settingLayout.setVisible(false);
            csmj.MJ_Data.SendCancelDismissRoom();
        });

        that.backLayout.setVisible(false);
        that.dismissLayout.setVisible(false);
        that.suredismissLayout.setVisible(false);
        that.settingLayout.setVisible(false);


        this.readyBtn = $.getNodeByName(mainNode,"ID_BUTTON_READY");
        this.readyBtn.addClickEventListener(function () {
            that.InitTable();
            csmj.MJ_Data.SendReady();
        });
        this.robotBtn = $.getNodeByName(mainNode,"ID_BUTTON_ROBOT");
        this.robotBtn.addClickEventListener(function () {
            csmj.MJ_Data.SendRobot();
        });
        if(cc.sys.isNative)
        {
            this.robotBtn.setVisible(false);
        }
        this.readyBtn.setVisible(false);
        this.backBtn = $.getNodeByName(mainNode,"ID_BUTTON_BACK");
        this.backBtn.addClickEventListener(function () {
            //csmj.MJ_Data.SendLeave();
            that.backLayout.setVisible(true);
            //cc.audioEngine.stopAllEffects();
            //cc.director.runScene(new dwc.DT_MainScene());
        });

        this.nodeRound = $.getNodeByName(mainNode,"ID_NODE_ROUND");

        this.nodeFeng = $.getNodeByName(mainNode,"ID_NODE_DNXB");
        this.nodeKeHuPai = $.getNodeByName(mainNode,"ID_NODE_TINGPAI");

        this.roomDescLabel = $.getNodeByName(mainNode,"ID_LABEL_ROOM_DESC");
        this.roomDescLabel.setString("");

        this.vecFeng = [];
        this.vecFeng[0] = $.getNodeByName(mainNode,"ID_SPRITE_D");
        this.vecFeng[1]  = $.getNodeByName(mainNode,"ID_SPRITE_N");
        this.vecFeng[2]  = $.getNodeByName(mainNode,"ID_SPRITE_X");
        this.vecFeng[3]  = $.getNodeByName(mainNode,"ID_SPRITE_B");
        this.vecFeng[0].runAction(cc.sequence(cc.fadeIn(1),cc.fadeOut(1)).repeatForever());
        this.vecFeng[1].runAction(cc.sequence(cc.fadeIn(1),cc.fadeOut(1)).repeatForever());
        this.vecFeng[2].runAction(cc.sequence(cc.fadeIn(1),cc.fadeOut(1)).repeatForever());
        this.vecFeng[3].runAction(cc.sequence(cc.fadeIn(1),cc.fadeOut(1)).repeatForever());

        this.userInfoLayout=$.getNodeByName(mainNode,"ID_LAYOUT_USERINFO");
        this.userInfoLayout.addClickEventListener(function () {
            that.userInfoLayout.setVisible(false);
        });
        this.userInfoLayout.setVisible(false);

        this.userInfoHeadImg=$.getNodeByName(mainNode,"ID_SPRITE_USERHEADIMG");
        this.useridLabel=$.getNodeByName(mainNode,"ID_LABEL_USERID");
        this.useridLabel.setString("ID: " + dwc.Myself.GetData().GetUid());

        this.usernickLabel=$.getNodeByName(mainNode,"ID_LABEL_USERNICK");
        this.usernickLabel.setString("" + dwc.Myself.GetData().GetNickName());

        this.useripLabel=$.getNodeByName(mainNode,"ID_LABEL_USERIP");
        this.useripLabel.setString("IP: " + dwc.Myself.GetData().GetIP());
        this.userList=[];
        for(var i=0;i<4;i++)
        {
            var userInfo={};
            userInfo.userInfoBG= $.getNodeByName(mainNode,"ID_LAYOUT_USERINFBG"+i);
            userInfo.userInfoBG.tag = i;

            userInfo.userName= $.getNodeByName(mainNode,"ID_LABEL_NAME"+i);
            userInfo.userHeadImg= $.getNodeByName(mainNode,"ID_SPRITE_HEADIMG"+i);
            userInfo.userScore= $.getNodeByName(mainNode,"ID_LABEL_SCORE"+i);
            userInfo.winScore= $.getNodeByName(mainNode,"ID_LABEL_WINSCORE"+i);
            userInfo.userZhuangSprite=$.getNodeByName(mainNode,"ID_SPRITE_ZHUANG"+i);
            userInfo.userYuYinBack=$.getNodeByName(mainNode,"ID_SPRITE_YUYINBG"+i);
            userInfo.userYuYinBack.setVisible(false);
            userInfo.userYuYinLabel=new cc.LabelTTF("","Arial",24,cc.size(220,90));
            userInfo.userYuYinLabel.setAnchorPoint(0.5,0.5);
            if(i!=2)
            {
                userInfo.userYuYinLabel.setPosition(120,65);
            }else{
                userInfo.userYuYinLabel.setPosition(120,45);
            }
            userInfo.userYuYinBack.addChild(userInfo.userYuYinLabel);
            userInfo.userReadySprite=$.getNodeByName(mainNode,"ID_SPRITE_READYSP"+i);
            userInfo.userReadySprite.setVisible(false);
            userInfo.userOfflineSprite=$.getNodeByName(mainNode,"ID_SPRITE_OFFLINE"+i);
            userInfo.userOfflineSprite.setVisible(false);
            userInfo.userInfoBG.setVisible(true);
            userInfo.userName.setVisible(true);
            userInfo.userScore.setVisible(true);
            userInfo.winScore.setVisible(true);
            userInfo.userZhuangSprite.setVisible(false);
            userInfo.userScore.setString("");
            userInfo.winScore.setString("");
            userInfo.luYinSprite=$.getNodeByName(mainNode,"ID_SPRITE_LUYINSP"+i);
            userInfo.luYinSprite.setVisible(false);
            userInfo.userInfoBG.tag=i;
            userInfo.userInfoBG.addClickEventListener(function (sender) {
                that.OnShowUserInfo(sender);
            });
            this.userList[i]=userInfo;
        }

        this.vecOpNode = [];
        this.vecOpNode["Chi"] = $.getNodeByName(mainNode,"ID_NODE_CHI");
        this.vecOpNode["Peng"] = $.getNodeByName(mainNode,"ID_NODE_PENG");
        this.vecOpNode["Gang"] = $.getNodeByName(mainNode,"ID_NODE_GANG");
        this.vecOpNode["Ting"] = $.getNodeByName(mainNode,"ID_NODE_TING");
        this.vecOpNode["Hu"] = $.getNodeByName(mainNode,"ID_NODE_HU");
        this.vecOpNode["Guo"] = $.getNodeByName(mainNode,"ID_NODE_GUO");

        this.vecOpBar = {};
        this.vecOpBar["Chi"] = $.getNodeByName(mainNode,"ID_BUTTON_CHI");
        this.vecOpBar["Chi"].addClickEventListener(function () {
            that.doOperatorBar("Chi");
        });
        this.vecOpBar["Peng"] = $.getNodeByName(mainNode,"ID_BUTTON_PENG");
        this.vecOpBar["Peng"].addClickEventListener(function () {
            that.doOperatorBar("Peng");
        });
        this.vecOpBar["Gang"] = $.getNodeByName(mainNode,"ID_BUTTON_GANG");
        this.vecOpBar["Gang"].addClickEventListener(function () {
            that.doOperatorBar("Gang");
        });
        this.vecOpBar["Ting"] = $.getNodeByName(mainNode,"ID_BUTTON_TING");
        this.vecOpBar["Ting"].addClickEventListener(function () {
            that.doOperatorBar("Ting");
        });
        this.vecOpBar["Hu"] = $.getNodeByName(mainNode,"ID_BUTTON_HU");
        this.vecOpBar["Hu"].addClickEventListener(function () {
            that.doOperatorBar("Hu");
        });
        this.vecOpBar["Guo"] = $.getNodeByName(mainNode,"ID_BUTTON_GUO");
        this.vecOpBar["Guo"].addClickEventListener(function () {
            that.doOperatorBar("Guo");
        });

        //这是浙江麻将的额外玩法，敲响
        this.vecOpNode["QiaoXiang"] = $.getNodeByName(mainNode,"ID_NODE_QIAOXIANG");
        this.vecOpBar["QiaoXiang"] = $.getNodeByName(mainNode,"ID_BUTTON_QIAOXIANG");
        this.vecOpBar["QiaoXiang"].addClickEventListener(function () {
            that.doOperatorBar("QiaoXiang");
        });


        this.m_OpBarNode = $.getNodeByName(mainNode,"ID_NODE_OPBAR");


        //test end
        //this.InitTable();
        this.initFourHandCard();
        this.initFourNewCard();
        this.initFourOutCard();
        this.initFourChiCard();
        this.initJieSuan();
        this.initEffect();

        this.renew_ui();


        //选择吃
        this.initChiPaiAnimation();
        this.initGangPaiAnimation();

        this.hideOperatorBar();
        //test
        //var array1 = [[11,12,13,]];
        //var array2 = [[11,12,13,],[4,5,6]];
        //var array3= [[11,11,12,13,],[4,4,5,6],[7,7,8,9]];

        //this.OnShowChiPai(array1);
        //this.OnShowGangPai(array3);
        //test end




    },
    initChiPaiAnimation: function () {
        var chiNode = this.chiNode = new cc.Node();
        this.chiNode.setVisible(false);
        chiNode.width = 1280;
        chiNode.height = 720;
        chiNode.setAnchorPoint(0.5,0.5);
        chiNode.setPosition(640,360);
        this.addChild(chiNode);

        this.chiNodeList = [];
        this.chiCardList = [];
        var chiBackPosList = [cc.p(610,450),cc.p(610,330),cc.p(610,210)];
        for(var i = 0 ;i<3;i++)
        {
            this.chiCardList[i] = [];
            var chiBack = new cc.Node();
            chiBack.width = 500;
            chiBack.height = 100;
            chiBack.setAnchorPoint(0,0);
            chiBack.setPosition(chiBackPosList[i]);
            chiBack.setVisible(false);
            chiNode.addChild(chiBack);
            this.chiNodeList[i] = chiBack;
            for(var j = 0 ;j<3;j++)
            {
                var card = new cc.Sprite("#0_1.png");
                card.setAnchorPoint(0.5,0.5);
                card.setPosition(75/2+j*75,100/2);
                chiBack.addChild(card);
                this.chiCardList[i][j] = card;
            }
            var chiBtn = new ccui.Button("btn_eat_cs.png","btn_eat_cs.png","btn_eat_cs.png",ccui.Widget.PLIST_TEXTURE);
            chiBtn.setAnchorPoint(0,0.5);
            chiBtn.setPosition(3*75+50,100/2);
            chiBtn.tag = i;
            chiBtn.addClickEventListener(function (sender) {this.OnChiButtonClick(sender);}.bind(this));
            chiBack.addChild(chiBtn);

        }

    },
    OnChiButtonClick: function (sender) {
        var idx = sender.tag;
        cc.log("选择吃牌!!!!!!!!!!!!!!!");

        this.chiNode.setVisible(false);
        var byMj = mj4.MajLogic.GetLastOutMj();

        var num = this.vecChiArray.length;
        var tag = sender.getTag();

        if(num == 1) {
            if(tag == 1)
            {
                csmj.MJ_Data.SendChiPai(byMj, this.vecChiArray[0][3]);
            }
        }else {
            csmj.MJ_Data.SendChiPai(byMj, this.vecChiArray[tag][3]);
        }

    },
    initGangPaiAnimation: function () {
        var gangNode = this.gangNode = new cc.Node();
        this.gangNode.setVisible(false);
        gangNode.width = 1280;
        gangNode.height = 720;
        gangNode.setAnchorPoint(0.5,0.5);
        gangNode.setPosition(this.width/2,this.height/2);
        this.addChild(gangNode);

        this.gangNodeList = [];
        this.gangCardList = [];
        var chiBackPosList = [cc.p(610,450),cc.p(610,330),cc.p(610,210)];
        for(var i = 0 ;i<3;i++)
        {
            this.gangCardList[i] = [];
            var gangBack = new cc.Node();
            gangBack.width = 500;
            gangBack.height = 100;
            gangBack.setAnchorPoint(0,0);
            gangBack.setPosition(chiBackPosList[i]);
            gangNode.addChild(gangBack);
            gangBack.setVisible(false);
            this.gangNodeList[i] = gangBack;
            for(var j = 0 ;j<4;j++)
            {
                var card = new cc.Sprite("#0_1.png");
                card.setAnchorPoint(0,0.5);
                card.setPosition(75/2+j*75,100/2);
                gangBack.addChild(card);
                this.gangCardList[i][j] = card;
            }
            var gangBtn = new ccui.Button("decision_sign_cs_2.png","decision_sign_cs_2.png","decision_sign_cs_2.png",ccui.Widget.PLIST_TEXTURE);
            gangBtn.setAnchorPoint(0,0.5);
            gangBtn.setPosition(4*75+50,100/2);
            gangBtn.tag = i;
            gangBtn.addClickEventListener(function (sender) {this.OnGangButtonClick(sender);}.bind(this));
            gangBack.addChild(gangBtn);
        }
    },

    OnGangButtonClick: function (sender) {
        try
        {
            var idx = sender.tag;
            cc.log("选择杠牌!!!!!!!!!!!!!!!");

            this.gangNode.setVisible(false);
            var tag = sender.getTag();
            var num = this.vecGangArray.length;
            if(num == 1)
            {
                if(tag == 1)
                {
                    csmj.MJ_Data.SendGangPai(this.vecGangArray[0][0],this.vecGangArray[0][1]);
                }
            }else{
                csmj.MJ_Data.SendGangPai(this.vecGangArray[tag][0],this.vecGangArray[tag][1]);

            }

        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
    },
    //显示吃界面
    OnShowChiPai: function (chiArray,_callback) {
        this.chiNode.setVisible(true);
        var num = chiArray.length;
        if(num == 1)
        {
            this.chiNodeList[0].setVisible(false);
            this.chiNodeList[1].setVisible(true);
            this.chiNodeList[2].setVisible(false);
            for(var i = 0;i<3;i++) {
                var mjPai = chiArray[0][i];
                if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
                {
                    if(mjPai == this.m_vecGuiPai[0])
                    {
                        mjPai = 33;
                    }
                }

                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";

                this.chiCardList[0][i].initWithSpriteFrameName(pngStr);
            }
        }
        if(num == 2)
        {
            this.chiNodeList[0].setVisible(true);
            this.chiNodeList[1].setVisible(true);
            this.chiNodeList[2].setVisible(false);
            for(var i = 0;i<3;i++) {
                var mjPai = chiArray[0][i];
                if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
                {
                    if(mjPai == this.m_vecGuiPai[0])
                    {
                        mjPai = 33;
                    }
                }
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";

                this.chiCardList[0][i].initWithSpriteFrameName(pngStr);
            }
            for(var i = 0;i<3;i++) {
                var mjPai = chiArray[1][i];
                if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
                {
                    if(mjPai == this.m_vecGuiPai[0])
                    {
                        mjPai = 33;
                    }
                }
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.chiCardList[1][i].initWithSpriteFrameName(pngStr);
            }


        }
        if(num == 3)
        {
            this.chiNodeList[0].setVisible(true);
            this.chiNodeList[1].setVisible(true);
            this.chiNodeList[2].setVisible(true);
            for(var i = 0;i<3;i++) {
                var mjPai = chiArray[0][i];
                if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
                {
                    if(mjPai == this.m_vecGuiPai[0])
                    {
                        mjPai = 33;
                    }
                }
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";

                this.chiCardList[0][i].initWithSpriteFrameName(pngStr);
            }
            for(var i = 0;i<3;i++) {
                var mjPai = chiArray[1][i];
                if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
                {
                    if(mjPai == this.m_vecGuiPai[0])
                    {
                        mjPai = 33;
                    }
                }
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.chiCardList[1][i].initWithSpriteFrameName(pngStr);
            }
            for(var i = 0;i<3;i++) {
                var mjPai = chiArray[2][i];
                if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
                {
                    if(mjPai == this.m_vecGuiPai[0])
                    {
                        mjPai = 33;
                    }
                }
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.chiCardList[2][i].initWithSpriteFrameName(pngStr);
            }
        }

    },
    //显示杠界面
    OnShowGangPai: function (gangArray) {
        this.gangNode.setVisible(true);
        var num = gangArray.length;
        if(num == 1)
        {
            this.gangNodeList[0].setVisible(false);
            this.gangNodeList[1].setVisible(true);
            this.gangNodeList[2].setVisible(false);
            for(var i = 0;i<4;i++)
            {
                var mjPai = gangArray[0][0];
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.gangCardList[1][i].initWithSpriteFrameName(pngStr);
            }
        }
        if(num == 2)
        {
            this.gangNodeList[0].setVisible(true);
            this.gangNodeList[1].setVisible(true);
            this.gangNodeList[2].setVisible(false);
            for(var i = 0;i<4;i++)
            {
                var mjPai = gangArray[0][0];
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.gangCardList[0][i].initWithSpriteFrameName(pngStr);
            }
            for(var i = 0;i<4;i++)
            {
                var mjPai = gangArray[1][0];
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.gangCardList[1][i].initWithSpriteFrameName(pngStr);
            }
        }
        if(num == 3)
        {
            this.gangNodeList[0].setVisible(true);
            this.gangNodeList[1].setVisible(true);
            this.gangNodeList[2].setVisible(true);
            for(var i = 0;i<4;i++)
            {
                var mjPai = gangArray[0][0];
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.gangCardList[0][i].initWithSpriteFrameName(pngStr);
            }
            for(var i = 0;i<4;i++)
            {
                var mjPai = gangArray[1][0];
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.gangCardList[1][i].initWithSpriteFrameName(pngStr);
            }
            for(var i = 0;i<4;i++)
            {
                var mjPai = gangArray[2][0];
                var type = parseInt(mjPai / 9);
                var index = mjPai - type * 9;

                var pngStr = "m_" + (type * 10 + index + 1) + ".png";
                this.gangCardList[2][i].initWithSpriteFrameName(pngStr);
            }
        }
    },
//鬼牌//////////////////////////////////////////////////////
    onMoPaiPaiAnimation: function (wViewChairID) {
        var that = this;
        //test
        var pngStr="#bm.png";
        var mopai_pos = this.m_vecHandCard[wViewChairID][13].getPosition();

        var moMj =  new cc.Sprite(pngStr);
        moMj.setPosition(cc.p(640,360));
        moMj.runAction(cc.sequence(cc.spawn(cc.moveTo(0.15,mopai_pos),cc.scaleTo(0.15,0.5)),
            cc.callFunc(function ()
            {
                moMj.removeFromParent();
            })));
        this.nodeMyHandMj.addChild(moMj);


    },
    //鬼牌//////////////////////////////////////////////////////
    onGuiPaiAnimation: function (mjList) {
        var that = this;
        //test
        var mjPai = mjList[0];
        var type=parseInt(mjPai / 9);
        var index=mjPai - type*9;

        var pngStr="#m_"+(type*10+index+1)+".png";
        //test end
        //this.frontMj =  new cc.Sprite("#empty_s.png");
        this.frontMj =  new cc.Sprite(pngStr);
        this.frontMj.setPosition(this.width/2,this.height/2);
        this.nodeMyHandMj.addChild(this.frontMj);
        this.frontMj.scale = 0.1;
        this.frontMj.setVisible(false);

        this.backMj =  new cc.Sprite("#bm_0.png");
        this.backMj.setPosition(this.width/2,this.height/2);
        this.nodeMyHandMj.addChild(this.backMj);
        this.backMj.scale = 0.1;
        this.backMj.setVisible(false);


        this.frontMj.runAction(cc.scaleTo(0.6,1));
        this.backMj.runAction(cc.sequence(cc.show(),
            cc.scaleTo(0.3,1),
            cc.orbitCamera(0.3,1,0,0,-115,0,0),cc.hide(),
            cc.callFunc(function (){
                cc.log("------------------579------------");
                that.frontMj.runAction(cc.sequence(cc.show(),
                    cc.orbitCamera(0.3,1,0,65,-65,0,0),
                    cc.hide(),
                    cc.callFunc(function ()
                    {
                        that.frontMj.removeFromParent();
                        that.backMj.removeFromParent();
                        that.onResultGuiPai(mjList);

                    }.bind(that),that)));

            }.bind(this),this)));


    },
    onResultGuiPai: function (mjList) {
        try
        {
            if(mjList)
            {
                if(mjList.length == 1)
                {
                    var mjPai = mjList[0];
                    var type=parseInt(mjPai / 9);
                    var index=mjPai - type*9;

                    var pngStr="#m_"+(type*10+index+1)+".png";

                    this.guiMJ0 =  new cc.Sprite(pngStr);
                    this.guiMJ0.setPosition(640,360);
                    this.nodeMyHandMj.addChild(this.guiMJ0);
                    this.guiMJ0.runAction(cc.sequence(cc.moveTo(0.1,cc.p(640,360)),cc.delayTime(0.3),cc.spawn(cc.moveTo(0.5,cc.p(90,612)),cc.scaleTo(1,0.5))));
                }
                if(mjList.length == 2)
                {
                    var mjPai = mjList[0];
                    var type=parseInt(mjPai / 9);
                    var index=mjPai - type*9;

                    var pngStr="#m_"+(type*10+index+1)+".png";

                    this.guiMJ0 =  new cc.Sprite(pngStr);
                    this.guiMJ0.setPosition(640,360);
                    this.nodeMyHandMj.addChild(this.guiMJ0);
                    this.guiMJ0.runAction(cc.sequence(cc.moveTo(0.2,cc.p(640-40,360)),cc.delayTime(0.3),cc.spawn(cc.moveTo(0.5,cc.p(56,612)),cc.scaleTo(1,0.5))));

                    var mjPai = mjList[1];
                    var type=parseInt(mjPai / 9);
                    var index=mjPai - type*9;

                    var pngStr="#m_"+(type*10+index+1)+".png";

                    this.guiMJ1 =  new cc.Sprite(pngStr);
                    this.guiMJ1.setPosition(640,360);
                    this.nodeMyHandMj.addChild(this.guiMJ1);
                    this.guiMJ1.runAction(cc.sequence(cc.moveTo(0.2,cc.p(640+40,360)),cc.delayTime(0.3),cc.spawn(cc.moveTo(0.5,cc.p(130,612)),cc.scaleTo(1,0.5))));
                }
            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
    },
    //马牌/////////////////////////////////////////
    onMaPaiAnimation: function () {
        var that = this;
        if(this.vecMaPai == undefined)
        {
            this.vecMaPai = [];
        }
        if(this.vecZhongMa == undefined)
        {
            this.vecZhongMa = [];
        }
        this.vecSPMaPai = [];
        for(var  i= 0;i<this.vecMaPai.length;i++)
        {
            var mjPai = this.vecMaPai[i];
            var type=parseInt(mjPai / 9);
            var index=mjPai - type*9;

            var pngStr="#m_"+(type*10+index+1)+".png";

            var maPai =  new cc.Sprite(pngStr);
            maPai.setPosition(this.width/2,this.height/2);
            maPai.tag = i;
            maPai.scale = 0.1;
            this.vecSPMaPai.push(maPai);
            this.nodeMyHandMj.addChild(maPai);
            this.onResultMaPai(maPai);
            if(this.vecZhongMa.indexOf(mjPai) < 0)
            {
                maPai.runAction(cc.sequence(cc.delayTime(1.5),cc.callFunc(function ()
                {
                    this.setColor(cc.color.GRAY);
                },maPai)));
            }
        }
        this.scheduleOnce(function(){
            that.showJieSuan();
        },4.0);
    },
    onResultMaPai: function (maPai) {
        var that = this;
        if(this.cntMaxMaPai == 2)
        {
            var maPaiPosList = [cc.p(this.width/2-100,this.height/2+60),cc.p(this.width/2,this.height/2+60),cc.p(this.width/2+100,this.height/2+60),
                cc.p(this.width/2-100,this.height/2-60),cc.p(this.width/2,this.height/2-60),cc.p(this.width/2+100,this.height/2-60)];
            maPai.runAction(cc.sequence(cc.scaleTo(0.5,1),
                cc.moveTo(0.6,maPaiPosList[maPai.tag]),
                //cc.delayTime(5),
                //cc.fadeOut(1),
                cc.callFunc(function ()
                {
                    //maPai.removeFromParent();
                },this)));
        }
        if(this.cntMaxMaPai == 4)
        {
            var maPaiPosList = [cc.p(this.width/2-100,this.height/2+60),cc.p(this.width/2,this.height/2+60),cc.p(this.width/2+100,this.height/2+60),
                cc.p(this.width/2-100,this.height/2-60),cc.p(this.width/2,this.height/2-60),cc.p(this.width/2+100,this.height/2-60)];
            maPai.runAction(cc.sequence(cc.scaleTo(0.5,1),
                cc.moveTo(0.6,maPaiPosList[maPai.tag]),
                cc.callFunc(function ()
                {
                    //maPai.removeFromParent();

                },this)));
        }
        if(this.cntMaxMaPai == 6)
        {
            var maPaiPosList = [cc.p(this.width/2-100,this.height/2+60),cc.p(this.width/2,this.height/2+60),cc.p(this.width/2+100,this.height/2+60),
                cc.p(this.width/2-100,this.height/2-60),cc.p(this.width/2,this.height/2-60),cc.p(this.width/2+100,this.height/2-60)];
            maPai.runAction(cc.sequence(cc.scaleTo(0.5,1),
                cc.moveTo(0.6,maPaiPosList[maPai.tag]),
                cc.callFunc(function ()
                {
                    //maPai.removeFromParent();

                },this)));
        }
    },



    OnShowHint:function (content,delay)
    {
        if(delay == undefined)
        {
            delay = 1.0;
        }
        var that=this;
        this.hintLabel.setString(content);
        this.hintBack.stopAllActions();
        this.hintLabel.stopAllActions();
        this.hintBack.setVisible(true);
        this.hintLabel.setPosition(370,56);
        this.hintBack.runAction(cc.sequence(cc.delayTime(delay),cc.callFunc(function () {
            that.hintBack.setVisible(false);
            that.hintLabel.setPosition(370,42);
        },this)));
        this.hintLabel.runAction(cc.moveTo(0.2,cc.p(370,56)));
    },
    showWinScoreEffect: function (pos, type, num,delay) {
        var vecPos = [cc.p(1280/2,200),cc.p(1000,720/2),cc.p(1280/2,720-200),cc.p(300,720/2)];
        var sprite = undefined;
        var numLabel = undefined;

        var that = this;
         if(type=="zimo"){
            if(num > 0)
            {
                sprite=new cc.Sprite("res/mj4/xlch/zimo.png");
                sprite.setPosition(vecPos[pos]);
                this.addChild(sprite);
                numLabel=new cc.LabelAtlas("0","res/mj4/xlch/shuzi-huang.png",40,40,'0');
                numLabel.setString(num);
                numLabel.setAnchorPoint(0,0.5);
                numLabel.setPosition(165,33);
                sprite.addChild(numLabel,200);
            }
            if(num < 0)
            {
                sprite=new cc.Sprite("res/mj4/xlch/zimo-hui.png");
                sprite.setPosition(vecPos[pos]);
                this.addChild(sprite);
                numLabel=new cc.LabelAtlas("0","res/mj4/xlch/shuzi-hui.png",40,40,'0');
                var abs_num = Math.abs(num);
                numLabel.setString(""+abs_num);
                numLabel.setAnchorPoint(0,0.5);
                numLabel.setPosition(165,33);
                sprite.addChild(numLabel,200);
            }
        }else if(type=="dianpao"){
            if(num > 0)
            {
                sprite=new cc.Sprite("res/mj4/xlch/dianpao.png");
                sprite.setPosition(vecPos[pos]);
                this.addChild(sprite);
                numLabel=new cc.LabelAtlas("0","res/mj4/xlch/shuzi-huang.png",40,40,'0');
                numLabel.setString(num);
                numLabel.setAnchorPoint(0,0.5);
                numLabel.setPosition(165,33);
                sprite.addChild(numLabel,200);
            }
            if(num < 0)
            {
                sprite=new cc.Sprite("res/mj4/xlch/dianpao-hui.png");
                sprite.setPosition(vecPos[pos]);
                this.addChild(sprite);
                numLabel=new cc.LabelAtlas("0","res/mj4/xlch/shuzi-hui.png",40,40,'0');
                var abs_num = Math.abs(num);
                numLabel.setString(""+abs_num);
                numLabel.setAnchorPoint(0,0.5);
                numLabel.setPosition(165,33);
                sprite.addChild(numLabel,200);
            }
        }
        if(sprite && numLabel)
        {
            if(!delay)
            {
                delay = 1.2;
            }
            numLabel.runAction(cc.sequence(cc.delayTime(delay),cc.fadeOut(1.2)));
            sprite.runAction(cc.sequence(cc.delayTime(delay),cc.fadeOut(1.2),cc.callFunc(function () {
                numLabel.removeFromParent();
                sprite.removeFromParent();

                //TOTDO
            },this)))
        }
    },
    //网络状态和点亮
    OnReloadWifiAndPower: function () {
        var str = undefined;
        if (cc.sys.os == cc.sys.OS_ANDROID) {
            str = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Tools", "WifiAndPowerStr", "(Ljava/lang/String;)Ljava/lang/String;", "");
            str = str.toLocaleLowerCase();
        }else if (cc.sys.os == cc.sys.OS_IOS) {
            str=jsb.reflection.callStaticMethod("RootViewController","commonCallBack");
        }
        if(str){
            var strArry=str.split("|");
            var power=strArry[0];
            var netStatus=strArry[1];
            if(netStatus=="no"){
                //cc.log("当前没有网络");
                this.netSprite.initWithFile("res/image/xinhao006.png");
            }else  if(netStatus=="4G"){
                //cc.log("当前网络为4G");
                this.netSprite.initWithFile("res/image/xinhao001.png");
            }else  if(netStatus=="wifi"){
                //cc.log("当前网络为wifi");
                this.netSprite.initWithFile("res/image/xinhao1.png");
            }else{
                //cc.log("当前网络为4G");
                this.netSprite.initWithFile("res/image/xinhao001.png");
            }

            this.netSprite.setAnchorPoint(1,0.5);
            this.powerBar.setPercent(parseFloat(power)*100);

        }
    },
    //音量大小
    OnVolume: function () {
        var lowPassResults = undefined;
        if (cc.sys.os == cc.sys.OS_ANDROID) {
            lowPassResults = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Tools", "getRealVolumeStr", "(Ljava/lang/String;)Ljava/lang/String;", "");
            //10000~~~~3200 100
            //335 370
            lowPassResults=parseInt(lowPassResults);
            if (lowPassResults > 2000) {
                this.volumeSprite.initWithFile("res/image/yinjie7.png");
            }else if (lowPassResults > 1500) {
                this.volumeSprite.initWithFile("res/image/yinjie6.png");
            }else if (lowPassResults > 1000) {
                this.volumeSprite.initWithFile("res/image/yinjie5.png");
            }else if (lowPassResults > 900) {
                this.volumeSprite.initWithFile("res/image/yinjie4.png");
            }else if (lowPassResults > 800) {
                this.volumeSprite.initWithFile("res/image/yinjie3.png");
            }else if (lowPassResults > 600) {
                this.volumeSprite.initWithFile("res/image/yinjie2.png");
            }else if (lowPassResults > 100) {
                this.volumeSprite.initWithFile("res/image/yinjie1.png");
            }else {
                this.volumeSprite.initWithFile("res/image/yinjie1.png");
            }
        }else if (cc.sys.os == cc.sys.OS_IOS) {
            lowPassResults=jsb.reflection.callStaticMethod("RootViewController","decibels");

            lowPassResults=parseInt(lowPassResults);
            if (360<lowPassResults&&lowPassResults<370) {
                this.volumeSprite.initWithFile("res/image/yinjie7.png");
            }else if (355<lowPassResults&&lowPassResults<=360) {
                this.volumeSprite.initWithFile("res/image/yinjie6.png");
            }else if (345<lowPassResults&&lowPassResults<=355) {
                this.volumeSprite.initWithFile("res/image/yinjie5.png");
            }else if (340<lowPassResults&&lowPassResults<=345) {
                this.volumeSprite.initWithFile("res/image/yinjie4.png");
            }else if (335<lowPassResults&&lowPassResults<=340) {
                this.volumeSprite.initWithFile("res/image/yinjie3.png");
            }else if (330<lowPassResults&&lowPassResults<=335) {
                this.volumeSprite.initWithFile("res/image/yinjie2.png");
            }else if (lowPassResults<335) {
                this.volumeSprite.initWithFile("res/image/yinjie1.png");
            }else {
                this.volumeSprite.initWithFile("res/image/yinjie1.png");
            }
        }
        this.volumeSprite.setAnchorPoint(0,0);
    },
    OnVoiceBtnClick: function (sender,type) {
        var that=this;

        switch(type)
        {
            case ccui.Widget.TOUCH_BEGAN:
                this.YuYinButtonsStartTime= new Date().getTime();
                break;
            case ccui.Widget.TOUCH_MOVED:
                break;
            case ccui.Widget.TOUCH_ENDED:

                cc.log("结束录音！！！！！！！！！！！！！！！！！");
                if(this.voiceBack.isVisible())
                {
                    this.OnOverVoice();
                }
                this.YuYinButtonsStartTime=0;
                break;
            case ccui.Widget.TOUCH_CANCELED:

                this.voiceBack.setVisible(false);
                cc.log("取消录音！！！！！！！！！");
                this.OnOverVoice();
                this.YuYinButtonsStartTime=0;
                break;
        }
    },
    OnOverVoice: function () {
        this.unschedule(this.OnVolume);
        var nowTime = new Date().getTime();
        var startTime=this.YuYinButtonsStartTime;
        $.record_seconds = (nowTime-startTime)/1000;
        if($.record_seconds < 0 || $.record_seconds > 60000)
        {
            $.record_seconds = 0;
        }
        this.voiceBack.setVisible(false);
        this.timeOut=false;

        if($.record_seconds > 1)
        {
            try
            {

                if (cc.sys.os == cc.sys.OS_ANDROID) {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Tools", "stopRecordVoice", "(Ljava/lang/String;)V", "");
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Tools", "uploadCurFile", "(Ljava/lang/String;)V", "");
                } else if (cc.sys.os == cc.sys.OS_IOS) {
                    jsb.reflection.callStaticMethod("RootViewController", "OnStopRecordVoice");
                }

            }catch (e)
            {
                cc.log(e.name + ":" + e.message);
            }
        }


        //cc.audioEngine.playMusic("res/audio/bgm1.mp3",true);
        //cc.audioEngine.setEffectsVolume(0.6);
        //cc.audioEngine.setMusicVolume(0.6);
    },
    OnPlayVoice: function (seconds,url) {
        try
        {
            if (cc.sys.os == cc.sys.OS_ANDROID) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Tools", "stopVoive", "(Ljava/lang/String;)V", url);
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Tools", "playVoive", "(Ljava/lang/String;)V", url);
            } else if (cc.sys.os == cc.sys.OS_IOS) {
                jsb.reflection.callStaticMethod("RootViewController", "OnPlayVoice:", url);
            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
    },

   OnLongPressed: function () {
       try
       {
           if(this.YuYinButtonsStartTime == 0){
               return;
           }
           var nowTime = new Date().getTime();
           var startTime=this.YuYinButtonsStartTime;
           if(startTime > 0 && nowTime - startTime > 1000)
           {
               cc.log("正在录音！！！！！！！！！！！！！！！！！");
               var myDate = new Date();
               var randName=myDate.getMonth().toString()+myDate.getDate().toString()+myDate.getDay().toString()+myDate.getHours().toString()+myDate.getMinutes().toString()+myDate.getSeconds().toString()+"";
               if (cc.sys.os == cc.sys.OS_ANDROID) {
                   jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Tools", "newRecordVoive", "(Ljava/lang/String;)V", randName+".mp3");
               } else if (cc.sys.os == cc.sys.OS_IOS) {
                   jsb.reflection.callStaticMethod("RootViewController", "OnRecordVoice");
               }
               this.schedule(this.OnVolume,0.3);
               this.voiceBack.setVisible(true);
           }else if(startTime > 0 && nowTime - startTime > 1000*60){
               this.timeOut=true;
               this.OnOverVoice();
           }else {
               this.voiceBack.setVisible(false);
           }
       }catch (e)
       {
           cc.log(e.name + ":" + e.message);
       }
    },

    _checkLeftTime : function()
    {
        if(this.m_bGameStarted)
        {
            if(this.m_nLeftTime)
            {
                this.m_nLeftTime--;
                this.lefttimeLabel.setString(""+this.m_nLeftTime);
                this.lefttimeLabel.setContentSize(18 * this.lefttimeLabel.string.length / 1, 30);
            }
        }
    },

    OnInvite : function(){
        var obj = {};
        var bundle = $.getBundleID();

        try
        {

            if (cc.sys.os == cc.sys.OS_ANDROID) {

                var iconUrl="http://img.cjpoker.com/csmj.png";
                var appUrl="http://a.app.qq.com/o/simple.jsp?pkgname=com.cjpoker.zjmj";
                var title="财神麻将房间号:"+"["+this.mRoomID+"]" + " 玩法:金华麻将";

                appUrl= "http://zjmj.cjpoker.com/app/index.html";
                

                obj.imageurl = iconUrl;
                obj.text = title;
                obj.title = title;
                obj.url = appUrl;
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "ShareToWeChat", "(Ljava/lang/String;)V", JSON.stringify(obj));
            }
            if (cc.sys.os == cc.sys.OS_IOS) {
                var iconUrl="http://img.cjpoker.com/csmj.png";
                var appUrl="http://a.app.qq.com/o/simple.jsp?pkgname=com.cjpoker.zjmj";
                var title="财神麻将房间号:"+"["+this.mRoomID+"]" + " 玩法:金华麻将";

                appUrl= "http://zjmj.cjpoker.com/app/index.html";

                jsb.reflection.callStaticMethod("RootViewController","OnSavePicWithName:shareType:shareContent:title:appUrl:text:iconUrl:","","wechat","auto",title,appUrl,title,iconUrl);
            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
    },
    OnTest: function () {
        this.num+=1;
        if(this.num>=4){
            this.num=0;
            this.index++;
        }
        this.OnSubChuPai(this.num,this.index);
    },
    renew_dnxb : function()
    {
        //this.nodeFeng.rotation = 90*((this.GetMeChairID()) % 4);
    },
    reset_left_time : function()
    {
        this.m_nLeftTime = 15;
    },
    renew_param : function()
    {
        if(this.roomDesc)
        {
            this.roomDescLabel.setString(this.roomDesc);
        }

    },
    renew_ui : function()
    {

        this.roundLabel.setString("" + this.m_nRound + "/" + this.m_nMaxRound);
        this.leftpaiLabel.setString(""+this.m_byYuPai);
        this.lefttimeLabel.setString(""+this.m_nLeftTime);
        this.lefttimeLabel.setContentSize(18 * this.lefttimeLabel.string.length / 1, 30);

        this.userList[0].userInfoBG.setVisible(true);
        this.userList[0].userZhuangSprite.setVisible(false);
        this.userList[0].userName.setVisible(true);
        this.userList[0].userScore.setVisible(true);
        this.userList[0].winScore.setVisible(true);


        for(var i=0;i<4;i++)
        {
            var wViewChairID=this.SwitchViewChairID(i);
            if(this.vecUser && this.vecUser[i] && this.vecUser[i].uid > 0)
            {

                this.userList[wViewChairID].userScore.setVisible(true);
                this.userList[wViewChairID].winScore.setVisible(true);

                this.userList[wViewChairID].userInfoBG.setVisible(true);

                this.userList[wViewChairID].userName.setString(this.vecUser[i].nickname);
                this.userList[wViewChairID].userName.setVisible(true);
                this.userList[wViewChairID].userScore.setVisible(true);
                this.userList[wViewChairID].winScore.setVisible(true);
                this.userList[wViewChairID].userScore.setString(this.vecUser[i].score);
                this.userList[wViewChairID].winScore.setString(this.m_vecRoundWinScore[i]);
            }else{
                this.userList[wViewChairID].userName.setVisible(false);
                this.userList[wViewChairID].userScore.setVisible(false);
                this.userList[wViewChairID].winScore.setVisible(false);
            }
            if(this.m_bGameStarted && mj4.MajLogic.m_byZhuang == i)
            {
                this.userList[wViewChairID].userZhuangSprite.setVisible(true);
            }else{
                this.userList[wViewChairID].userZhuangSprite.setVisible(false);
            }
            //头像////////////////////////////////////////////////////////////////////////
            var wViewChairID=this.SwitchViewChairID(i);
            if(this.vecUser[i] && this.vecUser[i].uid > 0)
            {
                if(this.vecUser[i].uid == 0)
                {
                    this.vecUser[i].state = 0;
                    this.vecUser[i].uid = 0;
                    this.userList[wViewChairID].userInfoBG.setVisible(false);
                    if(this.userList[wViewChairID].userHeadImg.getChildByTag(999)) {
                        this.userList[wViewChairID].userHeadImg.removeChildByTag(999, true);
                    }
                }else {
                    this.userList[wViewChairID].userInfoBG.setVisible(true);
                }
                this.userList[wViewChairID].userName.setString(this.vecUser[i].nickname);


                //this.userList[wViewChairID].userHeadImg.setScale(150/200,150/200);
                //this.userList[wViewChairID].userDifen.setString(this.vecUser[i].diFen);
                var userCoin = this.vecUser[i].coin + this.vecUser[i].diFen;
                if(userCoin < 0)
                {
                    userCoin = 0;
                }

                //this.userList[wViewChairID].userCoin.setString(userCoin);
            }else{
                this.userList[wViewChairID].userInfoBG.setVisible(false);
                if(this.userList[wViewChairID].userHeadImg.getChildByTag(999)) {
                    this.userList[wViewChairID].userHeadImg.removeChildByTag(999, true);
                }
            }

        }
    },
    reloadAvatar : function()
    {
        for(var i=0;i<4;i++) {
            var wViewChairID = this.SwitchViewChairID(i);
            if(this.vecUser[i] && this.vecUser[i].uid > 0 && this.vecUser[i].avatar_url)
            {

                this.userList[wViewChairID].uid = this.vecUser[i].uid;
                //test
                var avatar_url = this.vecUser[i].avatar_url;
                //avatar_url="http://img.cjpoker.com/csmj.png";
                //test end

                if (!this.userList[wViewChairID].userHeadImg.getChildByTag(999)) {
                    var param = {
                        avatar: this.vecUser[i].avatar,
                        gender: this.vecUser[i].gender,
                        avatar_url: avatar_url
                    };
                    dwc.GX_UserHeadImgManager.GetUrlImg(avatar_url, function (target, success, sprite, param) {
                        var headImageSprite = sprite;
                        if (success) {
                            headImageSprite.setScale(target.width / headImageSprite.width, target.height / headImageSprite.height);
                            headImageSprite.setAnchorPoint(cc.p(0.5, 0.5));
                            headImageSprite.setPosition(cc.p(target.width / 2, target.height / 2));
                            target.addChild(headImageSprite, 0, 999);
                        } else {
                            cc.log("get img error");
                            headImageSprite = new cc.Sprite("res/image/OtherImages/default_avatar.png");

                            headImageSprite.setScale(target.width / headImageSprite.width, target.height / headImageSprite.height);
                            headImageSprite.setAnchorPoint(cc.p(0.5, 0.5));
                            headImageSprite.setPosition(cc.p(target.width / 2, target.height / 2));
                            target.addChild(headImageSprite, 0, 999);
                        }
                    }, this.userList[wViewChairID].userHeadImg, param);
                }
            }
        }
    },
    renew_table : function()
    {
        var that = this;

        do
        {
            for(var i=0;i<4;i++)
            {
                var l_MajSide = that.GetMajSide(i);
                for(var j=0;j<20;j++)
                {
                    var pCard = this.m_vecOutCard[i][j];
                    if(pCard == undefined)
                    {
                        pCard = undefined;
                    }
                    var byMj = l_MajSide.outMj[j];
                    if (byMj > 42) {
                        pCard.setLiePai(255);
                    } else {
                        pCard.setLiePai(byMj);
                    }
                }
            }

        }while(false);

    },
    initFourHandCard: function () {
        var that = this;
        //test 逆时针从自己开始
        var rightList=[];
        var topList=[];
        var leftList=[];
        //四个人新牌坐标
        this.newCardPos=[];
        var mjPai=22;
        //test end
        this.m_vecKeHuCard = [];
        var posStart=cc.p(240,186);
        for(var i=0;i<13;i++){
            var card=new mj4.HAND_CARD(0,false,null,this);
            card.setPosition(cc.p(80 + 40*i,33));
            card.setVisible(false);
            card.setScale(0.5);
            this.nodeKeHuPai.addChild(card);
            this.m_vecKeHuCard[i]=card;
        }
        this.m_vecHandCard = [];
        //四个人的牌
        for(var i=0;i<4;i++){
            this.m_vecHandCard[i] = [];
            for(var j=0;j<14;j++){
                switch (i){
                    case 0:
                        var card=new mj4.MoveHAND_CARD(42,true,function(sender){
                            var factor = 1;
                            if(that.m_byTing[0] > 0)
                            {
                                factor = 0.8;
                            }
                            var byMj = sender.getPai();
                            that.ChuPai(byMj);
                            sender.runAction(cc.sequence(cc.moveTo(0.03,cc.p(640,240)),cc.callFunc(function () {

                            },this),cc.delayTime(0.2*factor)));
                        },this);
                        card.setPosition(cc.p(70+j*88,66));
                        card.setScale(92/75);
                        if(j==13){
                            card.setPosition(cc.p(70+13*88+10,66));
                        }
                        card.setNormalPosition(card.getPosition());
                        this.nodeMyHandMj.addChild(card,10);
                        this.m_vecHandCard[i].push(card);

                        break;
                    case 1:
                        var card=new cc.Sprite("#cm_1.png");
                        card.setPosition(cc.p(1080,240+j*30));
                        if(j==13){
                            card.setPosition(cc.p(1080,240+j*30+20));
                        }
                        this.spBG.addChild(card,30-j);
                        this.m_vecHandCard[i].push(card);
                        break;
                    case 2:
                        var card=new cc.Sprite("#cm_2.png");
                        card.setPosition(cc.p(860-j*37,720-80));
                        if(j==13){
                            card.setPosition(cc.p(860-j*37-20,720-80));
                        }
                        this.spBG.addChild(card,10);
                        this.m_vecHandCard[i].push(card);
                        break;
                    case 3:
                        var card=new cc.Sprite("#cm_3.png");
                        card.setPosition(cc.p(188,630-j*30));

                        if(j==13){
                            card.setPosition(cc.p(188,635-j*30-20));
                        }
                        this.spBG.addChild(card,10);
                        this.m_vecHandCard[i].push(card);
                        break;

                    default:
                        break;
                }
            }
        }
        for (var index = 0; index < 14; index++) {
            var pCard = this.m_vecHandCard[0][index];
            if (pCard == undefined) {

            }
        }
        this.newCardPos=[cc.p(300,720-120-13*30-20),
            cc.p(100+13*80+50,70),
            cc.p(80+13*80,200+13*30+20),
            cc.p(1280-400-13*35-20,720-50)
            ];

    },


    initFourNewCard: function () {
    },
    initFourOutCard: function () {
        var that = this;

        this.m_vecFourOutCard=[];
        var posList=[cc.p(1280/2,240),cc.p(1280-300,720/2),cc.p(1280/2,720-150),cc.p(300,720/2)];
        for(var i=0;i<4;i++){
            var card=new mj4.HAND_CARD(0,false,null,this);
            card.setPosition(posList[i]);
            card.setVisible(false);
            this.spBG.addChild(card,11);
            this.m_vecFourOutCard[i]=card;
        };

        this.m_vecOutCard=[];
        for(var idx=0;idx<4;idx++){
            switch (idx) {
                case 0:
                    this.leftOutList = [];
                    //test
                    var mjPai = 255;
                    //test end
                    for (var i = 0; i < 2; i++) {
                        for (var j = 0; j < 10; j++) {
                            var card = new mj4.OUT_CARD(idx, mjPai,0.76);

                            card.setPosition(480 + j * 40, 720-440 - i * 50);


                            that.spBG.addChild(card, 9);
                            card.setVisible(false);
                            that.leftOutList[i * 10 + j] = card;
                        }
                    }
                    this.m_vecOutCard.push(that.leftOutList);
                    break;
                case 1:
                    this.selfOutList = [];
                    //test
                    var mjPai = 255;
                    //test end
                    for (var i = 1; i >=0; i--) {
                        for (var j = 9; j >= 0; j--) {
                            var card = new mj4.OUT_CARD(idx, mjPai);

                            card.setPosition(902 + i * 48, 265 + j * 25);
                            that.spBG.addChild(card, 9);
                            card.setVisible(false);
                            that.selfOutList[i * 10 + j] = card;
                        }
                    }
                    this.m_vecOutCard.push(that.selfOutList);
                    break;
                case 2:
                    this.rightOutList = [];
                    //test
                    var mjPai = 11;
                    //test end
                    for (var i = 1; i >=0; i--) {
                        for (var j = 9; j >= 0; j--) {
                            var card = new mj4.OUT_CARD(idx, mjPai,0.76);
                            card.setPosition(844 - j * 40, 720 - 220 + i * 50);
                            that.spBG.addChild(card, 9);
                            card.setVisible(false);
                            that.rightOutList[i * 10 + j] = card;
                        }
                    }
                    this.m_vecOutCard.push(that.rightOutList);
                    break;
                case 3:
                    this.topOutList = [];
                    //test
                    var mjPai = 255;
                    //test end
                    for (var i = 0; i < 2; i++) {
                        for (var j = 0; j < 10; j++) {
                            var card = new mj4.OUT_CARD(idx, mjPai);

                            card.setPosition(420 - i * 48, 720 - 206 - j * 25);
                            that.spBG.addChild(card, 9);
                            card.setVisible(false);
                            that.topOutList[i * 10 + j] = card;
                        }
                    }
                    this.m_vecOutCard.push(that.topOutList);
                    break;
            }
        };
    },
    initFourChiCard: function () {
        this.m_vecChiCard = [];

        this.m_vecChiCard[0] = [];
        this.m_vecChiCard[1] = [];
        this.m_vecChiCard[2] = [];
        this.m_vecChiCard[3] = [];

        for (var i = 0;i<4;i++)
        {
            var mjPai = 1;
            this.m_vecChiCard[0][i*4+0] = new mj4.OUT_CARD(0,mjPai);
            this.m_vecChiCard[0][i*4+0].setPosition(cc.p(100+(i*3+0)*52 + i* 20,56));
            this.spBG.addChild(this.m_vecChiCard[0][i*4+0],3);
            this.m_vecChiCard[0][i*4+1] = new mj4.OUT_CARD(0,mjPai);
            this.m_vecChiCard[0][i*4+1].setPosition(cc.p(100+(i*3+1)*52 + i* 20,56));
            this.spBG.addChild(this.m_vecChiCard[0][i*4+1],3);
            this.m_vecChiCard[0][i*4+2] = new mj4.OUT_CARD(0,mjPai);
            this.m_vecChiCard[0][i*4+2].setPosition(cc.p(100+(i*3+2)*52 + i* 20,56));
            this.spBG.addChild(this.m_vecChiCard[0][i*4+2],3);
            this.m_vecChiCard[0][i*4+3] = new mj4.OUT_CARD(0,mjPai);
            this.m_vecChiCard[0][i*4+3].setPosition(cc.p(100+(i*3+1)*52 + i* 20,76));
            this.spBG.addChild(this.m_vecChiCard[0][i*4+3],3);


            this.m_vecChiCard[1][i*4+2] = new mj4.OUT_CARD(1,mjPai);
            this.m_vecChiCard[1][i*4+2].setPosition(cc.p(1070,200+(i*3+2)*26 + i*15));
            this.spBG.addChild(this.m_vecChiCard[1][i*4+2],3);
            this.m_vecChiCard[1][i*4+1] = new mj4.OUT_CARD(1,mjPai);
            this.m_vecChiCard[1][i*4+1].setPosition(cc.p(1070,200+(i*3+1)*26 + i*15));
            this.spBG.addChild(this.m_vecChiCard[1][i*4+1],3);
            this.m_vecChiCard[1][i*4+0] = new mj4.OUT_CARD(1,mjPai);
            this.m_vecChiCard[1][i*4+0].setPosition(cc.p(1070,200+(i*3+0)*26 + i*15));
            this.spBG.addChild(this.m_vecChiCard[1][i*4+0],3);


            this.m_vecChiCard[1][i*4+3] = new mj4.OUT_CARD(1,mjPai);
            this.m_vecChiCard[1][i*4+3].setPosition(cc.p(1070,200+(i*3+1)*26 + i*15+10));
            this.spBG.addChild(this.m_vecChiCard[1][i*4+3],3);


            this.m_vecChiCard[2][i*4+0] = new mj4.OUT_CARD(2,mjPai,0.76);
            this.m_vecChiCard[2][i*4+0].setPosition(cc.p(896-(i*3+0)*38 - i* 10,640));
            this.spBG.addChild(this.m_vecChiCard[2][i*4+0],3);
            this.m_vecChiCard[2][i*4+1] = new mj4.OUT_CARD(2,mjPai,0.76);
            this.m_vecChiCard[2][i*4+1].setPosition(cc.p(896-(i*3+1)*38 - i* 10,640));
            this.spBG.addChild(this.m_vecChiCard[2][i*4+1],3);
            this.m_vecChiCard[2][i*4+2] = new mj4.OUT_CARD(2,mjPai,0.76);
            this.m_vecChiCard[2][i*4+2].setPosition(cc.p(896-(i*3+2)*38 - i* 10,640));
            this.spBG.addChild(this.m_vecChiCard[2][i*4+2],3);
            this.m_vecChiCard[2][i*4+3] = new mj4.OUT_CARD(2,mjPai,0.76);
            this.m_vecChiCard[2][i*4+3].setPosition(cc.p(896-(i*3+1)*38 - i* 10,652));
            this.spBG.addChild(this.m_vecChiCard[2][i*4+3],3);


            this.m_vecChiCard[3][i*4+0] = new mj4.OUT_CARD(3,mjPai);
            this.m_vecChiCard[3][i*4+0].setPosition(cc.p(190,640-(i*3+0)*26 - i*15));
            this.spBG.addChild(this.m_vecChiCard[3][i*4+0],3);
            this.m_vecChiCard[3][i*4+1] = new mj4.OUT_CARD(3,mjPai);
            this.m_vecChiCard[3][i*4+1].setPosition(cc.p(190,640-(i*3+1)*26 - i*15));
            this.spBG.addChild(this.m_vecChiCard[3][i*4+1],3);
            this.m_vecChiCard[3][i*4+2] = new mj4.OUT_CARD(3,mjPai);
            this.m_vecChiCard[3][i*4+2].setPosition(cc.p(190,640-(i*3+2)*26 - i*15));
            this.spBG.addChild(this.m_vecChiCard[3][i*4+2],3);
            this.m_vecChiCard[3][i*4+3] = new mj4.OUT_CARD(3,mjPai);
            this.m_vecChiCard[3][i*4+3].setPosition(cc.p(190,640-(i*3+1)*26 - i*15+10));
            this.spBG.addChild(this.m_vecChiCard[3][i*4+3],3);
        }
    },
    initJieSuan : function(){
        var that = this;
        var mainNode = this.mainNode;
        this.jiesuanList=[];
        for(var i=0;i<4;i++) {
            var jiesuanInfo = {};
            jiesuanInfo.nicknameLabel = $.getNodeByName(mainNode, "ID_LABEL_JS_NICKNAME" + i);
            jiesuanInfo.winScoreLabel = $.getNodeByName(mainNode, "ID_LABEL_JS_WINSCORE" + i);
            jiesuanInfo.loseScoreLabel = $.getNodeByName(mainNode, "ID_LABEL_JS_LOSESCORE" + i);
            jiesuanInfo.roundScoreLabel = $.getNodeByName(mainNode, "ID_LABEL_JS_ROUNDSCORE" + i);
            this.jiesuanList.push(jiesuanInfo);
        }

        this.foldBtn = $.getNodeByName(mainNode, "ID_BUTTON_FOLD");
        this.foldBtn.addClickEventListener(function () {
            that.nodeJieSuanBG.setVisible(false);
            that.foldBtn.setVisible(false);
            that.spreadBtn.setVisible(true);
        });
        this.spreadBtn = $.getNodeByName(mainNode, "ID_BUTTON_SPREAD");
        this.spreadBtn.addClickEventListener(function () {
            that.nodeJieSuanBG.setVisible(true);
            that.spreadBtn.setVisible(false);
            that.foldBtn.setVisible(true);
        });
        this.againBtn = $.getNodeByName(mainNode, "ID_BUTTON_AGAIN");
        this.againBtn.addClickEventListener(function () {
            that.nodeJieSuan.setVisible(false);
            that.InitTable();
            jhmj.MJ_Data.SendReady();
        });
        this.reportBtn = $.getNodeByName(mainNode, "ID_BUTTON_REPORT");
        this.reportBtn.addClickEventListener(function () {
            if(that.final_report)
            {
                var dlg=new jhmj.FinalReportDialog(this);
                //this.target.addChild(dlg,999);
                that.addChild(dlg,999);
                dlg.showReport(that.final_report);
                that.final_report = null;
            }
        });
        this.reportBtn.setVisible(false);
        this.nodeJieSuan.setVisible(false);
    },
    InitTable : function()
    {
        this.RepositTable();
    },
    RepositTable : function()
    {
        if(this.guiMJ0)
        {
            this.guiMJ0.removeFromParent();
        }
        if(this.guiMJ1)
        {
            this.guiMJ1.removeFromParent();
        }
        this.m_vecGuiPai = [];

        this.isNeedMoMa = false;

        this.vecMaPai = [];
        this.vecZhongMa = [];
        this.m_vecChiSide = [[255,255,255,255],[255,255,255,255],[255,255,255,255],[255,255,255,255]];


        for(var i = 0 ;i < 4;i++) {
            var wViewChairID = this.SwitchViewChairID(i);
            for (var k = 0; k < 14; k++) {
                if (wViewChairID == 0) {
                    this.m_vecHandCard[wViewChairID][k].scale = 92/75;
                } else {
                    this.m_vecHandCard[wViewChairID][k].scale = 1;
                }
            }
        }
        this.nodeJieSuan.setVisible(false);

        if(this.m_bGameStarted)
        {
            var pos=[cc.p(66,230),cc.p(1220,490),cc.p(970,648),cc.p(60,490)];
            for(var i=0;i<4;i++){
                this.userList[i].userInfoBG.setPosition(pos[i]);
            }
        }else{
            var pos=[cc.p(640,180),cc.p(1200,490),cc.p(640,600),cc.p(80,490)];
            for(var i=0;i<4;i++){
                this.userList[i].userInfoBG.setPosition(pos[i]);
            }
        }

        for(var m=0;m<14;m++)
        {
            this.m_vecHandCard[1][m].initWithSpriteFrameName("cm_1.png");
            this.m_vecHandCard[2][m].initWithSpriteFrameName("cm_2.png");
            this.m_vecHandCard[3][m].initWithSpriteFrameName("cm_3.png");
        }


        this.m_waitState = "STATE_NULL";
        mj4.MajLogic.InitPaiJu();
        this.m_opRight = [0,0,0,0,0,0];
        this.m_byTing = [0,0,0,0];
        this.m_vecRoundWinScore = [0,0,0,0];
        this.m_gangXuanSeq = [[0, 0], [0, 0], [0, 0], [0, 0]];
        this.m_chiXuanSeq=[255,255,255,255];

        this.m_bGameStarted = false;

        this.readyBtn.setVisible(true);
        //this.readyBtn.setVisible(false);
        this.nodeFeng.setVisible(false);
        this.nodeRound.setVisible(false);
        this.nodeKeHuPai.setVisible(false);


        this.lefttimeLabel.setVisible(false);

        this.chatBtn.setVisible(true);


        this.voiceBtn.setVisible(true);

        for(var i=0;i<4;i++) {
            this.m_vecFourOutCard[i].setVisible(false);
        }

        for(var i=0;i<4;i++)
        {
            //this.userList[i].userInfoBG.setVisible(false);
            for(var j=0;j<14;j++)
            {
                if(this.m_vecHandCard[i][j]) {
                    this.m_vecHandCard[i][j].setVisible(false);
                }
            }
            for(var j=0;j<16;j++)
            {
                if(this.m_vecChiCard[i][j]) {
                    this.m_vecChiCard[i][j].setVisible(false);
                }
            }
            for(var j=0;j<20;j++) {
                if(this.m_vecOutCard[i][j])
                {
                    this.m_vecOutCard[i][j].setVisible(false);
                }
            }
        }
        this.currentSprite.setVisible(false);
        this.userList[0].userInfoBG.setVisible(true);
        this.userList[0].userZhuangSprite.setVisible(false);
        this.userList[0].userName.setString(dwc.Myself.GetData().GetNickName());
        this.userList[0].userScore.setVisible(true);
        this.userList[0].winScore.setVisible(true);
    },

    setZhuangPos : function(seat)
    {
        var pos = [cc.p(286,248),cc.p(1170,460),cc.p(900,656),cc.p(168,500)];

        this.userList[seat].userZhuangSprite.setVisible(true);
    },
    setCurrentFeng : function(seat)
    {
        this.vecFeng[0].setVisible(false);
        this.vecFeng[1].setVisible(false);
        this.vecFeng[2].setVisible(false);
        this.vecFeng[3].setVisible(false);
        if(seat < 4)
        {
            this.vecFeng[seat].setVisible(true);
        }
    },

    initEffect : function()
    {
        this.actionList=[];
        var posList=[cc.p(640,210),cc.p(900,360),cc.p(640,520),cc.p(380,360)];
        for(var i=0;i<4;i++){
            var actionSprite=new cc.Sprite("#decision_sign_1.png");
            actionSprite.setPosition(posList[i]);
            this.addChild(actionSprite,15);
            actionSprite.setVisible(false);
            this.actionList[i]=actionSprite;
        }
    },
    playChiEffect: function (seat) {

        var that = this;
        this.actionList[seat].initWithSpriteFrameName("btn_eat_cs.png");
        this.actionList[seat].runAction(cc.sequence(cc.show(),cc.fadeIn(0.1),cc.fadeOut(1.5),cc.callFunc(function () {
            if(seat == 0)
            {
                that.spriteEffectFinished(seat,"Chi");
            }


        })));

        if(seat == 0 || seat == 2)
        {
            var nowTime = new Date().getTime();
            cc.audioEngine.playEffect("res/mj4/sound/pai/girl/chi_"+Math.ceil(nowTime%3)+".mp3",false);
        }else{
            var nowTime = new Date().getTime();
            cc.audioEngine.playEffect("res/mj4/sound/pai/boy/chi_"+Math.ceil(nowTime%3)+".mp3",false);
        }
    },
    playPengEffect: function (seat) {
        var that = this;
        this.actionList[seat].initWithSpriteFrameName("btn_peng_cs.png");
        this.actionList[seat].runAction(cc.sequence(cc.show(),cc.fadeIn(0.1),cc.fadeOut(1.5),cc.callFunc(function () {
            if(seat == 0) {
                that.spriteEffectFinished(seat, "Peng");
            }
        })));
        if(seat == 0 || seat == 2)
        {
            var nowTime = new Date().getTime();
            cc.audioEngine.playEffect("res/mj4/sound/pai/girl/peng_"+Math.ceil(nowTime%3)+".mp3",false);
        }else{
            var nowTime = new Date().getTime();
            cc.audioEngine.playEffect("res/mj4/sound/pai/boy/peng_"+Math.ceil(nowTime%3)+".mp3",false);
        }

    },
    playGangEffect: function (seat) {
        var that = this;
        this.actionList[seat].initWithSpriteFrameName("btn_gang_cs.png");
        this.actionList[seat].runAction(cc.sequence(cc.show(),cc.fadeIn(0.1),cc.fadeOut(1.5),cc.callFunc(function () {
            if(seat == 0) {
                that.spriteEffectFinished(seat, "Gang");
            }

        })));
        //播放音效
        if(seat == 0 || seat == 2)
        {
            var nowTime = new Date().getTime();
            cc.audioEngine.playEffect("res/mj4/sound/pai/girl/gang_"+Math.ceil(nowTime%3)+".mp3",false);
        }else{
            var nowTime = new Date().getTime();
            cc.audioEngine.playEffect("res/mj4/sound/pai/boy/gang_"+Math.ceil(nowTime%3)+".mp3",false);
        }
    },
    playTingEffect : function(seat){

    },
    playHuEffect: function (seat) {
        return;
        var that = this;
        this.actionList[seat].initWithSpriteFrameName("btn_win_cs.png");
        this.actionList[seat].runAction(cc.sequence(cc.show(),cc.fadeIn(0.1),cc.fadeOut(1.5),cc.callFunc(function () {
            if(seat == 0) {
                that.spriteEffectFinished(seat, "Hu");
            }

        })));

    },
    SortCard: function (byHandCard,byHandMjCount)// static void SortCard(BYTE byHandCard[],BYTE byHandMjCount);
    {
        if(byHandMjCount === undefined)
        {
            byHandMjCount = 13;
        }
        for(var i = 0;i < byHandMjCount - 1;i++)
        {
            for(var j = i;j < byHandMjCount;j++)
            {
                if(this.m_vecGuiPai)
                {
                    if(this.m_vecGuiPai.indexOf(byHandCard[j]) >= 0)
                    {
                        if(this.m_vecGuiPai.indexOf(byHandCard[i]) < 0) {
                            var tempValue = byHandCard[i];
                            byHandCard[i] = byHandCard[j];
                            byHandCard[j] = tempValue;
                        }
                    }else if(this.m_vecGuiPai.indexOf(byHandCard[i]) < 0 && byHandCard[i] > byHandCard[j])
                    {
                        var tempValue = byHandCard[i];
                        byHandCard[i] = byHandCard[j];
                        byHandCard[j] = tempValue;
                    }
                }else{
                    if(byHandCard[i] > byHandCard[j])
                    {
                        var tempValue = byHandCard[i];
                        byHandCard[i] = byHandCard[j];
                        byHandCard[j] = tempValue;
                    }
                }
            }
        }
        if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
        {
            var cntBai = 0;
            var cntCS = 0;
            var vec1 = [];
            var vec2 = [];
            for (var i = 0; i < byHandMjCount; i++)
            {
                if(byHandCard[i] == 33 && byHandCard[i] != this.m_vecGuiPai[0]) {
                    cntBai++;
                }else{
                    if (byHandCard[i] < this.m_vecGuiPai[0])
                    {
                        vec1.push(byHandCard[i]);
                    }
                    if (byHandCard[i] > this.m_vecGuiPai[0])
                    {
                        vec2.push(byHandCard[i]);
                    }
                    if (byHandCard[i] == this.m_vecGuiPai[0])
                    {
                        cntCS++;
                    }
                }
            }
            for (var i = 0; i < byHandMjCount-cntCS; i++)
            {
                if(i<vec1.length)
                {
                    byHandCard[i+cntCS] = vec1[i];
                }
                if(i>=vec1.length && i<byHandMjCount-vec2.length)
                {
                    byHandCard[i+cntCS] = 33;
                }
                if(i>=vec1.length+cntBai)
                {
                    byHandCard[i+cntCS] = vec2[i-vec1.length-cntBai];
                }
            }
        }
        return byHandCard;
    },

    IsChiXuan : function()
    {
        var that = this;
        this.m_chiXuanSeq=[255,255,255,255];
        var cntChiXuan = this.GetChiXuan(that.GetMajSide(0).Maj,mj4.MajLogic.GetLastOutMj(),this.m_chiXuanSeq);
        if(cntChiXuan > 1)
        {
            return true;
        }else{
            return false;
        }
    },

    IsGangXuan : function() {
        var that = this;
        this.m_gangXuanSeq = [[0, 0], [0, 0], [0, 0], [0, 0]];
        var l_MajSide = that.GetMajSide(0);
        if (this.m_CurrentUser == 0) {
            if (this.m_byTing[0] > 0) {
                return false;
            } else {
                var cntGangXuan = this.GetGangXuan(l_MajSide.Maj, l_MajSide.block, l_MajSide.GetMoPai(), this.m_gangXuanSeq);
                if (cntGangXuan > 1) {
                    return true;
                } else {
                    return false;
                }
            }
        } else {

            var cntGangXuan = this.GetGangXuan(l_MajSide.Maj, l_MajSide.block, mj4.MajLogic.GetLastOutMj(), this.m_gangXuanSeq);
            if (cntGangXuan > 1) {
                return true;
            } else {
                return false;
            }
        }
    },
    IsTongHuaSe3:function(  byMj1,  byMj2, byMj3 )
    {
        if(this.m_vecGuiPai && this.m_vecGuiPai.length>0) {
            if (byMj1 == 33) byMj1 = this.m_vecGuiPai[0];
            if (byMj2 == 33) byMj2 = this.m_vecGuiPai[0];
            if (byMj3 == 33) byMj3 = this.m_vecGuiPai[0];
        }
        if (byMj1<=8  && byMj2<=8  && byMj3<=8)
        {
            return	true;
        }
        if (byMj1>= 9 &&byMj1<=17  && byMj2>= 9 &&byMj2<=17  && byMj3>= 9 &&byMj3<=17)
        {
            return	true;
        }
        if (byMj1>= 18 &&byMj1<=26  && byMj2>= 18 &&byMj2<=26  && byMj3>= 18 &&byMj3<=26)
        {
            return	true;
        }
        if((byMj1 == byMj2)  && (byMj2 == byMj3) && (byMj1 < 34))
        {
            return	true;
        }
        return	false;
    },
    IsTongHuaSe2:function( byMj1,  byMj2)
    {
        if(this.m_vecGuiPai && this.m_vecGuiPai.length>0) {
            if (byMj1 == 33) byMj1 = this.m_vecGuiPai[0];
            if (byMj2 == 33) byMj2 = this.m_vecGuiPai[0];
        }
        if (byMj1<=8  && byMj2<=8)
        {
            return	true;
        }
        if (byMj1>= 9 &&byMj1<=17  && byMj2>= 9 &&byMj2<=17)
        {
            return	true;
        }
        if (byMj1>= 18 &&byMj1<=26  && byMj2>= 18 &&byMj2<=26)
        {
            return	true;
        }
        if((byMj1 == byMj2) && (byMj1 < 34))
        {
            return	true;
        }
        return false;
    },

    IsTongYangPai:function( byMj1,  byMj2)
    {
        if(this.m_vecGuiPai && this.m_vecGuiPai.length>0) {
            if (byMj1 == 33) byMj1 = this.m_vecGuiPai[0];
            if (byMj2 == 33) byMj2 = this.m_vecGuiPai[0];
        }
        if(byMj1 == byMj2)
        {
            return true;
        }else{
            return false;
        }
    },
    GetChiXuan: function(byHandMj,byMj,chiSeq)
    {
        //风,字不能上
        if( byMj > 26 && byMj != 33)
        {
            return 0;
        }

        var cntCS = 0;
        if(this.m_vecGuiPai && this.m_vecGuiPai.length>0&& this.m_vecGuiPai[0] != 255)
        {
            for (var i = 0; i < 14-1; i++)
            {
                if (byHandMj[i] == this.m_vecGuiPai[0])
                {
                    cntCS++;
                }
            }
            if(byMj == 33) {
                byMj = this.m_vecGuiPai[0];
            }
        }

        var chiInfo = [0,0,0];			//吃牌信息, 0-无吃牌,1-**@型, 2-*@*, 4-@**型
        var pos2 = true;var pos1 = true;var pos = true;

        for( var i=cntCS; i<14-1; i++ )
        {
            //**@
            if( this.IsTongYangPai(byHandMj[i],byMj-2) && pos2 )
            {
                for( var j=i; j<14-1; j++ )
                {
                    if( this.IsTongYangPai(byHandMj[j] , byMj-1) && this.IsTongHuaSe3(byMj,byMj-1,byMj-2))
                    {
                        //chiSeq[0] = byMj - 2;			// 吃牌类型1
                        chiInfo[0] = 1;
                        break;
                    }
                }
                pos2 = false;
            }
            //*@*
            else if( this.IsTongYangPai(byHandMj[i],byMj-1 ))
            {
                for( var j=i; j<14-1; j++ )
                {
                    if( this.IsTongYangPai(byHandMj[j] , byMj+1)  && this.IsTongHuaSe3(byMj,byMj-1,byMj+1))
                    {
                        //chiSeq[1] = byMj - 2;			//吃牌类型2
                        chiInfo[1] = 1;
                        break;
                    }
                }
                pos1 = false;
            }
            //@**
            else if( this.IsTongYangPai(byHandMj[i] , byMj+1))
            {
                for( var j=i; j<14-1; j++ )
                {
                    if( this.IsTongYangPai(byHandMj[j] , byMj+2)  && this.IsTongHuaSe3(byMj,byMj+1,byMj+2))
                    {
                        //chiSeq[2] = byMj;			//吃牌类型2
                        chiInfo[2] = 1;
                        break;
                    }
                }
                pos = false;
            }
        }
        if(chiInfo[0] > 0)
        {
            chiSeq[0] = byMj - 2;			// 吃牌类型1
        }
        if(chiInfo[1] > 0)
        {
            chiSeq[1] = byMj - 1;			// 吃牌类型1
        }
        if(chiInfo[2] > 0)
        {
            chiSeq[2] = byMj + 1;			// 吃牌类型1
        }
        var cntChi = 0;
        for (var i = 0;i < 3;i++)
        {
            if(chiInfo[i] > 0)
            {
                cntChi += 1;
            }
        }
        return cntChi;
    },
    /*//麻将类型结构
     enum BLOCKSTYLE
     {
     BLOCK_NULL	 = 0,				//无
     BLOCK_CHI,						//吃牌结构
     BLOCK_SUN,	 					//顺序结构
     BLOCK_PENG,	 					//碰子结构,3个相同
     BLOCK_KE,						//刻子结构,3个相同,非碰
     BLOCK_GANG,						//杠子结构,4个相同
     BLOCK_AN_GANG ,					//暗杠
     BLOCK_CHI_BAI,
     };
     vecBlock = [[0,1],[0,1],[0,1],[0,1]];//这是一个4个数组，每个数字对应一个"[类型,麻将]"结构体
     */
    GetGangXuan: function (byHandMj,vecBlock,byMj,gangSeq,bZiMo)
    {
        var byTmpHandMj = [];
        for( var j=0; j<14; j++ )
        {
            byTmpHandMj.push(byHandMj[j]);
        }
        var bZiMoGang = false;
        if(byHandMj[14-1] == 255)
        {
            byTmpHandMj[14-1] = byMj;
            bZiMoGang = false;
        }else{
            bZiMoGang = true;
        }
        this.SortCard(byTmpHandMj,14);
        var index = 0;
        for( var i=0; i<4; i++ )
        {
            for( var j=0; j<14; j++ ) {
                if (vecBlock[i][0] == 3 && vecBlock[i][1] == byTmpHandMj[j]) {
                    if (bZiMoGang == true) {
                        gangSeq[index][0] = 2;
                        gangSeq[index][1] = byTmpHandMj[j];

                        index++;
                    }
                }
            }
        }
        for( var j=0; j<=10; j++ )
        {
            if(byTmpHandMj[j+0] == byTmpHandMj[j+1] && byTmpHandMj[j+1] == byTmpHandMj[j+2] && byTmpHandMj[j+2] == byTmpHandMj[j+3] && byTmpHandMj[j+0] < 34 )
            {
                if(bZiMoGang == true){
                    gangSeq[index][0] = 4;
                }else{
                    gangSeq[index][0] = 1;
                }
                gangSeq[index][1] = byTmpHandMj[j+0];
                index++;
            }
        }
        return index;
    },

    spriteEffectFinished: function (seat,SenderAction){
        return;
        if(SenderAction == "Chi")
        {
            if (this.m_waitState == "STATE_CHIXUAN")
            {
                var nChiType = 0;
                switch (this.m_chiXuanIndex)
                {
                    case 1:
                    {
                        nChiType = 1;
                    }
                        break;
                    case 2:
                    {
                        nChiType = 2;
                    }
                        break;
                    case 3:
                    {
                        nChiType = 4;
                    }
                        break;
                }
                if(seat == this.mChairID)
                {
                    csmj.MJ_Data.SendChiPai(mj4.MajLogic.GetLastOutMj(),nChiType);
                }

            }else {
                for (var i =0;i<3;i++)
                {
                    if (this.m_chiXuanSeq[i] >= 0 && this.m_chiXuanSeq[i] < 27) {
                        var nChiType = 0;
                        switch (i) {
                            case 0:
                            {
                                nChiType = 1;
                            }
                                break;
                            case 1:
                            {
                                nChiType = 2;
                            }
                                break;
                            case 2:
                            {
                                nChiType = 4;
                            }
                                break;
                        }
                        if(seat == this.mChairID) {
                            csmj.MJ_Data.SendChiPai(mj4.MajLogic.GetLastOutMj(), nChiType);
                        }
                        break;
                    }
                }
            }
        }else if(SenderAction == "Peng")
        {
            //csmj.MJ_Data.SendPengPai(mj4.MajLogic.GetLastOutMj());
        }else if(SenderAction == "Gang")
        {
            if (this.m_waitState == "STATE_GANGXUAN")
            {
                this.m_waitState = "STATE_NULL";
                if (this.m_gangXuanIndex)
                {
                    if(seat == this.mChairID) {
                        //csmj.MJ_Data.SendGangPai(this.m_gangXuanSeq[this.m_gangXuanIndex][1], this.m_gangXuanSeq[this.m_gangXuanIndex - 1][0]);
                    }
                }
            }else{
                this.m_waitState = "STATE_NULL";
                for (var i =0;i<4;i++)
                {
                    if (this.m_gangXuanSeq[i][0] != 0)
                    {
                        if(seat == this.mChairID) {
                            //csmj.MJ_Data.SendGangPai(this.m_gangXuanSeq[i][1], this.m_gangXuanSeq[i][0]);
                        }
                        break;
                    }
                }
            }
        }else if(SenderAction == "Ting")
        {
            //this.m_waitState = "STATE_TINGWAIT";
        }else if(SenderAction == "KeHuPai")
        {

        }else if(SenderAction == "Hu" || SenderAction == "ZiMo" || SenderAction == "FangQiang")
        {
            if(seat == this.mChairID) {
                //csmj.MJ_Data.SendHuPai();
            }
        }
    },
    //聊天界面及逻辑处理///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    initChatView: function (mainNode) {
        var that=this;

        //第一个是庄的位置，不用
        this.playerPosList=[cc.p(630,230),cc.p(1130,270),cc.p(630,580),cc.p(150,270)];
        this.playerChatPosList=[cc.p(760,250),cc.p(960,450),cc.p(760,580),cc.p(310,450)];
    },

    chatEmotionBtnClick: function (idx) {
        //this.chatBack.setVisible(false);
        //var idx=sender.tag;
        this.OnShowHint("表情功能尚未开启");
        return;
        csmj.MJ_Data.SendBiaoQing(idx);
        //this.showBiaoQing(idx);
    },
    OnSubBiaoQing : function(uid,seat,index)   {
        var wViewChairID=this.SwitchViewChairID(seat);
        this.showBiaoQing(wViewChairID,index);
    },

    showBiaoQing : function(seat,idx)
    {
        try {

        }catch(e)
        {
            cc.log(e.name + ":" + e.message);
        }
        try {

            var that = this;
            var pos=this.playerChatPosList[seat];
            //var pngStr="res/chat/game_expression"+idx+".png"
            //var emotionSprite=new cc.Sprite(pngStr);
            //emotionSprite.setAnchorPoint(0.5,0.5);
            //emotionSprite.setPosition(pos);
            //this.spBG.addChild(emotionSprite,100);
            //emotionSprite.runAction(
            //    cc.sequence(cc.moveTo(0.6,cc.p(pos.x,pos.y+50)),
            //        cc.moveTo(0.6,cc.p(pos.x,pos.y)),
            //        cc.delayTime(0.6),
            //        cc.callFunc(function () {
            //            emotionSprite.removeFromParent();
            //        },this)))
            if(this.emotionSprite)
            {
                this.emotionSprite.removeFromParent();
                this.emotionSprite = null;
            }
            var str="#expression"+idx+"1"+".png";
            if(idx==11||idx==14||idx==16)
            {
                str="#expression"+idx+"01"+".png";
            }
            this.emotionSprite = new cc.Sprite();
            this.emotionSprite.setPosition(pos);
            this.spBG.addChild(this.emotionSprite,100);
            var animationFrames = [];
            var count=1;
            var str ="expression"+idx+"1"+".png";
            if(idx==11||idx==14||idx==16)
            {
                str="expression"+idx+"01"+".png";
            }
            var frame = cc.spriteFrameCache.getSpriteFrame(str);
            animationFrames.push(frame);
            while (frame)
            {
                count++;
                var str ="expression"+idx+count+".png";
                if(idx==11||idx==14||idx==16)
                {
                    if(count<11)
                    {
                        str="expression"+idx+"0"+count+".png";
                    }else
                    {
                        str="expression"+idx+count+".png";
                    }

                }
                var frame = cc.spriteFrameCache.getSpriteFrame(str);
                if(frame)
                {
                    animationFrames.push(frame);
                }
            };
            var animation = new cc.Animation(animationFrames, 0.2);
            this.emotionSprite.runAction(cc.animate(animation).repeatForever());
            this.emotionSprite.runAction(cc.sequence(
                cc.delayTime(3),
                cc.callFunc(function ()
                {
                    that.emotionSprite.removeFromParent();

                }.bind(this),this)));
        }catch(e)
        {
            cc.log(e.name + ":" + e.message);
        }


    },
    chatYuYinBtnClick: function (idx) {
        //this.chatBack.setVisible(false);
        //var idx=sender.tag;
        csmj.MJ_Data.SendYuYin(idx);

    },

    OnSubVoice : function(uid,seat,seconds,url)   {
        if(this.m_vecVoiceHistory == undefined)
        {
            this.m_vecVoiceHistory = [];
        }
        for(var i=0;i<this.m_vecVoiceHistory.length;i++)
        {
            if(this.m_vecVoiceHistory[i][3] == url)
            {
                return;
            }
        }
        this.m_vecVoiceSeq.push([uid,seat,seconds,url]);
        this.m_vecVoiceHistory.push([uid,seat,seconds,url]);

    },
    OnSubYuYin : function(uid,seat,index)   {
        var wViewChairID=this.SwitchViewChairID(seat);
        this.showYuYin(wViewChairID,index);
    },
    showYuYin : function(seat,idx)
    {
        if(seat == 0 || seat == 2)
        {
            var audioPath="res/audio/msg/female/fix_msg_"+idx+".mp3";
            cc.audioEngine.playEffect(audioPath,false);
        }else{
            var audioPath="res/audio/msg/male/fix_msg_"+idx+".mp3";
            cc.audioEngine.playEffect(audioPath,false);
        }


        this.OnShowYuYinText(seat,idx);
    },
    chatTextMsg: function (msg) {
        csmj.MJ_Data.SendTextMsg(msg);
    },
    //收到服务器聊天消息  显示用户普通聊天msg
    OnSubChatTextMsg: function (uid,seat,msg) {
        var wViewChairID=this.SwitchViewChairID(seat);
        this.userList[wViewChairID].userYuYinLabel.setString(msg);
        this.userList[wViewChairID].userYuYinBack.runAction(cc.sequence(
            cc.show(),
            cc.delayTime(3),
            cc.hide()));
    },
    //显示用户语音聊天
    OnShowYuYinText: function (seat,textIndex) {

        this.userList[seat].userYuYinLabel.setString(csmj.MJ_Data.YuYinChatText[textIndex]);
        this.userList[seat].userYuYinBack.runAction(cc.sequence(
            cc.show(),
            cc.delayTime(3),
            cc.hide()));
    },
    showSongLi : function(idx)
    {

    },
    ChuPai : function(byMj)
    {
        var that=this;

        this.OnUserOutMj(0,byMj);

        if(that.m_waitState == "STATE_TINGWAIT") {
            csmj.MJ_Data.SendChuPai(byMj, 1);
        }else{
            csmj.MJ_Data.SendChuPai(byMj, 0);
        }

        that.checkHandMj();
        //that.renew_hand_pai();
        //that.renew_table();
    },
    TanPai : function()
    {
        for(var i=1;i<4;i++)
        {

        }
    },
    renew_hand_pai : function()
    {
        var that = this;

        do
        {
            for(var i=0;i<4;i++)
            {
                var l_MajSide = that.GetMajSide(i);
                var byHandCount = l_MajSide.GetHandMjCount();
                var byHandLieCount = l_MajSide.GetBlockCount() * 3;

                if(i == 0)
                {
                    for (var index = 0; index < byHandLieCount; index++) {
                        var pCard = this.m_vecHandCard[0][index];
                        if (pCard == undefined) {
                            pCard = undefined;
                        }
                        pCard.setStandPai(255);
                    }

                    for (var index = 0;index<14;index++)
                    {
                        if(index < byHandCount)
                        {
                            var pCard = this.m_vecHandCard[0][index+byHandLieCount];
                            if(pCard == undefined)
                            {
                                pCard = undefined;
                            }
                            var byMj = l_MajSide.Maj[index];
                            if (byMj > 42) {
                                pCard.setStandPai(255);
                            } else {
                                if(byMj == undefined)
                                {
                                    pCard.setStandPai(byMj);
                                }
                                pCard.setStandPai(byMj);
                                pCard.setGuiPai(this.m_vecGuiPai,"res/mj4/zjmj/gui_icon.png");
                            }
                        }else{
                            if(index+byHandLieCount < 14)
                            {
                                var pCard = this.m_vecHandCard[0][index+byHandLieCount];
                                pCard.setStandPai(255);
                            }
                        }
                    }
                    if(l_MajSide.GetMoPai() != 255 && l_MajSide.GetHandMjCount() % 3 == 2) {
                        var byMj = l_MajSide.Maj[14 - 1];
                        var pCard = this.m_vecHandCard[0][14 - 1];
                        if (pCard == undefined) {
                            pCard = undefined;
                        }
                        if (byMj > 42) {
                            pCard.setStandPai(255);
                        } else {
                            pCard.setStandPai(byMj);
                            pCard.setGuiPai(this.m_vecGuiPai, "res/mj4/zjmj/gui_icon.png");
                        }
                    }

                    if(this.m_bQiaoXiangHu)
                    {
                        var pCard = this.m_vecHandCard[0][14 - 1];
                        if (pCard == undefined) {
                            pCard = undefined;
                        }
                        pCard.setStandPai(42);
                    }
                }else{
                    var byHandCount = l_MajSide.GetHandMjCount();
                    for (var index = 0; index < byHandLieCount; index++) {
                        var pCard = this.m_vecHandCard[i][index];
                        pCard.setVisible(false);
                    }

                    for (var index = 0;index<14;index++)
                    {
                        if(index < byHandCount) {
                            var pCard = this.m_vecHandCard[i][index + byHandLieCount];
                            if (pCard == undefined) {
                                pCard = undefined;
                            }
                            var byMj = l_MajSide.Maj[index];
                            if (byMj != 255) {
                                pCard.setVisible(true);
                            } else {
                                pCard.setVisible(false);
                                break;
                            }
                        }else{
                            if(index+byHandLieCount < 14) {
                                var pCard = this.m_vecHandCard[i][index+byHandLieCount];
                                pCard.setVisible(false);
                            }
                        }
                    }
                    if(l_MajSide.GetMoPai() == 255 && l_MajSide.GetHandMjCount() % 3 != 2)
                    {
                        var pCard = this.m_vecHandCard[i][13];
                        pCard.setVisible(false);
                    }else{
                        pCard.setVisible(true);
                    }
                }

            }

        }while(false);
    },
    renew_chi_pai : function()
    {
        var that = this;
        for (var i = 0;i < 4;i++ )
        {
            var kSide = that.GetMajSide(i);

            for(var k =0; k < 4; ++k)
            {
                var bIsBlock = true;
                var kBlock = kSide.block[k];

                var byBlockMj = [255,255,255,255];

                switch(kBlock[0])
                {
                    case 1: // BLOCK_CHI = 1
                        byBlockMj[0] = kBlock[1];
                        byBlockMj[1] = kBlock[1] + 1;
                        byBlockMj[2] = kBlock[1] + 2;
                        byBlockMj[3] = 255;
                        if(this.m_vecGuiPai && this.m_vecGuiPai.length>0)
                        {
                            if(byBlockMj[0] == this.m_vecGuiPai[0])
                            {
                                byBlockMj[0] = 33;
                            }
                            if(byBlockMj[1] == this.m_vecGuiPai[0])
                            {
                                byBlockMj[1] = 33;
                            }
                            if(byBlockMj[2] == this.m_vecGuiPai[0])
                            {
                                byBlockMj[2] = 33;
                            }
                        }
                        break;
                    case 3: // BLOCK_PENG = 3
                        byBlockMj[0] = kBlock[1];
                        byBlockMj[1] = kBlock[1];
                        byBlockMj[2] = kBlock[1];
                        byBlockMj[3] = 255;
                        break;
                    case 5: // BLOCK_GANG = 5
                        byBlockMj[0] = kBlock[1];
                        byBlockMj[1] = kBlock[1];
                        byBlockMj[2] = kBlock[1];
                        byBlockMj[3] = kBlock[1];
                        break;
                    case 6: // BLOCK_AN_GANG
                        byBlockMj[0] = 42;
                        byBlockMj[1] = 42;
                        byBlockMj[2] = 42;
                        if(i==0)
                        {
                            byBlockMj[3] = kBlock[1];
                        }else{
                            byBlockMj[3] = 42;
                        }

                        break;
                    default:
                    {
                        bIsBlock = false;
                    }
                        break;
                }

                var wViewSide = this.m_vecChiSide[i][k];

                this.m_vecChiCard[i][k*4+0].setLiePai(byBlockMj[0]);
                this.m_vecChiCard[i][k*4+1].setLiePai(byBlockMj[1]);
                this.m_vecChiCard[i][k*4+2].setLiePai(byBlockMj[2]);
                this.m_vecChiCard[i][k*4+3].setLiePai(byBlockMj[3]);

                if(wViewSide < 4)
                {
                    if(kBlock[0] == 1)
                    {
                        this.m_vecChiCard[i][k*4+0].setArrow(false,wViewSide);
                        this.m_vecChiCard[i][k*4+1].setArrow(false,wViewSide);
                        this.m_vecChiCard[i][k*4+2].setArrow(false,wViewSide);
                        this.m_vecChiCard[i][k*4+3].setArrow(false,wViewSide);
                        if(kSide.chiMj[k] < 42)
                        {
                            if(byBlockMj[0] == kSide.chiMj[k])
                            {
                                this.m_vecChiCard[i][k*4+0].setArrow(true,wViewSide);
                            }
                            if(byBlockMj[1] == kSide.chiMj[k])
                            {
                                this.m_vecChiCard[i][k*4+1].setArrow(true,wViewSide);
                            }
                            if(byBlockMj[2] == kSide.chiMj[k])
                            {
                                this.m_vecChiCard[i][k*4+2].setArrow(true,wViewSide);
                            }
                        }
                    }else{
                        this.m_vecChiCard[i][k*4+0].setArrow(true,wViewSide);
                        this.m_vecChiCard[i][k*4+1].setArrow(true,wViewSide);
                        this.m_vecChiCard[i][k*4+2].setArrow(true,wViewSide);
                        this.m_vecChiCard[i][k*4+3].setArrow(true,wViewSide);
                    }
                }
            }
        }
    },

    enableHandMj : function(bEnable)
    {
        for (var i = 0;i<14;i++)
        {
            var pCard = this.m_vecHandCard[0][i];
            if (pCard)
            {
                pCard.enablePop(bEnable);
            }
            this.m_bIsHandMjEnabled = bEnable;
        }
    },
    showOperatorBar : function( bChiRight, bPengRight, bGangRight, bTingRight, bHuRight, bGuoRight )
    {
        var pos6 = [cc.p(220,290),cc.p(346,290),cc.p(472,290),cc.p(598,290),cc.p(725,290),cc.p(840,290)];
        var pos5 = [cc.p(220,290),cc.p(373,290),cc.p(526,290),cc.p(680,290),cc.p(840,290)];
        var pos4 = [cc.p(380,290),cc.p(530,290),cc.p(680,290),cc.p(840,290)];
        var pos3 = [cc.p(520,290),cc.p(680,290),cc.p(840,290)];
        var pos2 = [cc.p(680,290),cc.p(840,290)];
        var that = this;

        var bIsChi = false; var bIsPeng = false;var bIsGang = false;var bIsTing = false;var bIsHu = false;var bIsGuo  = false;
        var cntRight = 0;
        var opNodeArray = [];

        if(this.m_byTing[0])
        {
            if(bHuRight == true || (bHuRight >= 1 && bHuRight <= 20))
            {
                bIsHu = true;
                opNodeArray[cntRight++] =  this.vecOpNode["Hu"];
            }
        }else{
            if(this.m_bQiaoXiangHu)
            {
                bIsHu = true;
                opNodeArray[cntRight++] =  this.vecOpNode["QiaoXiang"];
            }else {
                if (bChiRight == true || (bChiRight >= 1 && bChiRight < 10)) {
                    bIsChi = true;
                    opNodeArray[cntRight++] = this.vecOpNode["Chi"];
                }
                if (bPengRight == true || (bPengRight >= 1 && bPengRight < 10)) {
                    bIsPeng = true;
                    opNodeArray[cntRight++] = this.vecOpNode["Peng"];
                }
                if (bGangRight == true || (bGangRight >= 1 && bGangRight < 10)) {
                    bIsGang = true;
                    opNodeArray[cntRight++] = this.vecOpNode["Gang"];
                }
                if (bTingRight == true || (bTingRight >= 1 && bTingRight <= 20)) {
                    bIsTing = true;
                    opNodeArray[cntRight++] = this.vecOpNode["Ting"];
                }
                if (bHuRight == true || (bHuRight >= 1 && bHuRight <= 20)) {
                    bIsHu = true;

                    opNodeArray[cntRight++] = this.vecOpNode["Hu"];
                }
            }
        }
        if(bIsChi || bIsPeng || bIsGang || bIsHu)
        {
            this.m_OpBarNode.setVisible(true);
        }else{
            return;
        }

        if(bIsChi && bIsPeng && bIsGang && bIsTing && bIsHu && bIsGuo)
        {
            return;
        }

        opNodeArray[cntRight++] =  this.vecOpNode["Guo"];

        this.vecOpNode["Chi"].setVisible(bIsChi);
        this.vecOpNode["Peng"].setVisible(bIsPeng);
        this.vecOpNode["Gang"].setVisible(bIsGang);
        this.vecOpNode["Ting"].setVisible(bIsTing);
        this.vecOpNode["Hu"].setVisible(bIsHu);
        this.vecOpNode["Guo"].setVisible(true);

        this.vecOpNode["QiaoXiang"].setVisible(bIsHu);
        if(this.m_bQiaoXiangHu)
        {
            this.vecOpNode["Hu"].setVisible(false);
            this.vecOpNode["QiaoXiang"].setVisible(bIsHu);
        }else{
            this.vecOpNode["Hu"].setVisible(bIsHu);
            this.vecOpNode["QiaoXiang"].setVisible(false);
        }
        if(opNodeArray.length == 6)
        {
            for(var i=0;i<opNodeArray.length;i++)
            {
                opNodeArray[i].setPosition(pos6[i]);
            }
        }
        if(opNodeArray.length == 5)
        {
            for(var i=0;i<opNodeArray.length;i++)
            {
                opNodeArray[i].setPosition(pos5[i]);
            }
        }
        if(opNodeArray.length == 4)
        {
            for(var i=0;i<opNodeArray.length;i++)
            {
                opNodeArray[i].setPosition(pos4[i]);
            }
        }
        if(opNodeArray.length == 3)
        {
            for(var i=0;i<opNodeArray.length;i++)
            {
                opNodeArray[i].setPosition(pos3[i]);
            }
        }
        if(opNodeArray.length == 2)
        {
            for(var i=0;i<opNodeArray.length;i++)
            {
                opNodeArray[i].setPosition(pos2[i]);
            }
        }
        if(bIsHu)
        {
            for (var i = 0;i<14;i++) {
                var pCard = this.m_vecHandCard[0][i];
                if (pCard) {
                    pCard.setTingXuanVisible(false);
                }
            }
        }
    },
    hideOperatorBar : function()
    {
        try{
            this.chiNode.setVisible(false);
            this.gangNode.setVisible(false);
            this.m_OpBarNode.setVisible(false);

            this.m_waitState = "STATE_NULL";
        }catch(e)
        {
            cc.log(e.name + ":" + e.message);
        }
    },
    doOperatorBar : function(tag)
    {
        var that = this;

        if(tag == "Chi") {
            if (that.m_waitState == "STATE_CHIXUAN") {
                return;
            } else {
                if (that.m_waitState != "STATE_CHIXUAN_WAIT") {
                    if (that.IsChiXuan()) {
                        that.m_chiXuanIndex = 0;
                        that.m_waitState = "STATE_CHIXUAN_WAIT";
                        that.s_fPassTime = 0;
                        that.s_iNumber = 0;

                        //var array1 = [[11,12,13,]];
                        //var array2 = [[11,12,13,],[4,5,6]];
                        //var array3= [[11,11,12,13,],[4,4,5,6],[7,7,8,9]];

                        //this.OnShowChiPai(array1);
                        //this.OnShowGangPai(array3);
                        //that.OnShowChiPai();
                        this.vecChiArray = [];
                        var byMj = mj4.MajLogic.GetLastOutMj();
                        if (this.m_vecGuiPai && this.m_vecGuiPai.length > 0 && byMj == 33) {
                            byMj = this.m_vecGuiPai[0];
                        }
                        var _chiArrayIndex = 0;
                        for (var i = 0; i < 3; i++) {
                            if (this.m_chiXuanSeq[i] >= 0 && this.m_chiXuanSeq[i] < 27) {
                                var nChiType = 0;
                                switch (i) {
                                    case 0:
                                    {
                                        nChiType = 1;
                                        this.vecChiArray[_chiArrayIndex] = [byMj - 2, byMj - 1, byMj, 1];
                                        _chiArrayIndex++;
                                        break;
                                    }
                                    case 1:
                                    {
                                        nChiType = 2;
                                        this.vecChiArray[_chiArrayIndex] = [byMj - 1, byMj, byMj + 1, 2];
                                        _chiArrayIndex++;
                                        break;
                                    }
                                    case 2:
                                    {
                                        nChiType = 4;
                                        this.vecChiArray[_chiArrayIndex] = [byMj, byMj + 1, byMj + 2, 4];
                                        _chiArrayIndex++;
                                        break;
                                    }
                                }
                            }
                        }

                        this.OnShowChiPai(this.vecChiArray);

                    } else {
                        //that.playChiEffect(this.mChairID);
                        //that.hideOperatorBar();

                        for (var i = 0; i < 3; i++) {
                            if (this.m_chiXuanSeq[i] >= 0 && this.m_chiXuanSeq[i] < 27) {
                                var nChiType = 0;
                                switch (i) {
                                    case 0:
                                    {
                                        nChiType = 1;
                                    }
                                        break;
                                    case 1:
                                    {
                                        nChiType = 2;
                                    }
                                        break;
                                    case 2:
                                    {
                                        nChiType = 4;
                                    }
                                        break;
                                }

                                csmj.MJ_Data.SendChiPai(mj4.MajLogic.GetLastOutMj(), nChiType);
                                that.hideOperatorBar();

                                break;
                            }
                        }
                    }
                }
            }
        }
        if(tag == "Peng") {

            csmj.MJ_Data.SendPengPai();
            //that.playPengEffect(0);
            that.hideOperatorBar();

        }
        if(tag == "Gang") {
            if (that.m_waitState == "STATE_GANGXUAN") {
                return;
            } else {
                if (that.m_waitState != "STATE_GANGXUAN_WAIT") {
                    if (that.IsGangXuan()) {
                        that.m_gangXuanIndex = 0;
                        that.m_waitState = "STATE_GANGXUAN_WAIT";
                        that.s_fPassTime = 0;
                        that.s_iNumber = 0;
                        //that.OnShowGangPai();

                        this.vecGangArray = [];

                        var _gangArrayIndex = 0;
                        for (var i = 0; i < 3; i++) {
                            if (that.m_gangXuanSeq[i][0] != 0) {
                                this.vecGangArray[_gangArrayIndex] = [that.m_gangXuanSeq[i][1], that.m_gangXuanSeq[i][0]];
                                _gangArrayIndex++;
                            }
                        }

                        that.OnShowGangPai(that.vecGangArray);

                        that.showOperatorBar(false, false, true, false, false, false);
                    } else {
                        //that.playGangEffect(0);
                        //that.hideOperatorBar();
                        this.m_waitState = "STATE_NULL";
                        for (var i = 0; i < 4; i++) {
                            if (this.m_gangXuanSeq[i][0] != 0) {
                                csmj.MJ_Data.SendGangPai(this.m_gangXuanSeq[i][1], this.m_gangXuanSeq[i][0]);
                                that.hideOperatorBar();
                                break;
                            }
                        }
                    }
                }
            }
        }
        if(tag == "Ting") {
            //that.playTingEffect(0);
            that.hideOperatorBar();
            that.m_waitState = "STATE_TINGWAIT";
        }
        if(tag == "QiaoXiang") {
            csmj.MJ_Data.SendHuPai();
            that.hideOperatorBar();
        }
        if(tag == "Hu") {

            //that.playHuEffect(0);
            csmj.MJ_Data.SendHuPai();
            that.hideOperatorBar();
        }
        if(tag == "Guo") {
            csmj.MJ_Data.SendGuoPai();
            that.hideOperatorBar();
            this.m_bQiaoXiangHu = 0;
            this.renew_hand_pai();
        }
        if(tag == "QiaoXiang") {

            csmj.MJ_Data.SendHuPai();
            that.hideOperatorBar();
        }
    },
    onEnter: function () {
        this._super();

        csmj.MJ_Data.m_uiGameLayer = this;
        $.runningScene = this;
    },

    onExit: function () {
        this._super();

        csmj.MJ_Data.m_uiGameLayer = null;
        $.runningScene = null;
    },
    OnShowUserInfo: function (sender) {
        //test /////////////////////////
        var wViewChairID = sender.tag;

        try {
            var realseat = this.SwitchRealChairID(wViewChairID);
            this.userInfoLayout.setVisible(true);
            this.usernickLabel.setString(this.vecUser[realseat].nickname);
            this.useridLabel.setString("ID: " + this.vecUser[realseat].uid);
            if(this.vecUser[realseat].ip)
            {
                this.useripLabel.setString(""+this.vecUser[realseat].ip);
            }else{
                this.useripLabel.setString("");
            }


            var avatar_url = this.vecUser[realseat].avatar_url;
            //avatar_url="http://img.cjpoker.com/csmj.png";
            //test end
            if (this.userInfoHeadImg.getChildByTag(999)) {
                this.userInfoHeadImg.removeChildByTag(999);
            }
            if (!this.userInfoHeadImg.getChildByTag(999)) {
                var param = {
                    avatar: this.vecUser[realseat].avatar,
                    gender: this.vecUser[realseat].gender,
                    avatar_url: avatar_url
                };
                dwc.GX_UserHeadImgManager.GetUrlImg(avatar_url, function (target, success, sprite, param) {
                    var headImageSprite = sprite;
                    if (success) {
                        headImageSprite.setScale(target.width / headImageSprite.width, target.height / headImageSprite.height);
                        headImageSprite.setAnchorPoint(cc.p(0.5, 0.5));
                        headImageSprite.setPosition(cc.p(target.width / 2, target.height / 2));
                        target.addChild(headImageSprite, 0, 999);
                    } else {
                        cc.log("get img error");
                        headImageSprite = new cc.Sprite("res/image/OtherImages/default_avatar.php");

                        headImageSprite.setScale(target.width / headImageSprite.width, target.height / headImageSprite.height);
                        headImageSprite.setAnchorPoint(cc.p(0.5, 0.5));
                        headImageSprite.setPosition(cc.p(target.width / 2, target.height / 2));
                        target.addChild(headImageSprite, 0, 999);
                    }
                }, this.userInfoHeadImg, param);
            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
    },
    //加入该类型游戏
    OnSubJoin : function()   {

    },
    //离开
    OnSubLeave : function()   {
        cc.audioEngine.playEffect("res/mj4/sound/leave_room.wav",false);
    },
    OnSubTable : function(userInfoList)   {
        if(this.vecUser == undefined)
        {
            this.vecUser = [null,null,null,null,null,null];
        }
        for(var seat=0;seat<4;seat++)
        {
            if(this.vecUser[seat] == undefined)
            {
                this.vecUser[seat] = {};
            }
            this.vecUser[seat].uid = userInfoList[seat].uid;
            this.vecUser[seat].seat = seat;
            this.vecUser[seat].score = userInfoList[seat].score;
            this.vecUser[seat].nickname = userInfoList[seat].nickname;
            this.vecUser[seat].avatar = userInfoList[seat].avatar;
            this.vecUser[seat].gender = userInfoList[seat].gender;
            this.vecUser[seat].state = userInfoList[seat].state;
            this.vecUser[seat].offline = false;
            this.vecUser[seat].ip = userInfoList[seat].ip;
        }
        var cntUser = 0;
        for(var i=0;i<4;i++)
        {
            if (this.vecUser && this.vecUser[i] && this.vecUser[i].uid > 0)
            {
                cntUser++;
            }
        }
        if(this.m_bTableStarted)
        {
            this.inviteBtn.setVisible(false);
        }else
        {
            if(cntUser>= 4) {
                this.inviteBtn.setVisible(false);
            }else{
                this.inviteBtn.setVisible(true);
            }
        }

        if(this.m_bGameStarted)
        {
            this.readyBtn.setVisible(false);
        }else{
            if(cntUser>= 4)
            {
                if(this.vecUser[this.mChairID].state != US_READY)
                {
                    this.readyBtn.setVisible(true);
                }else{
                    this.readyBtn.setVisible(false);
                }
                for(var k=0;k<4;k++)
                {
                    var wViewChairID=this.SwitchViewChairID(k);
                    if(this.vecUser[k].state == US_READY)
                    {
                        this.userList[wViewChairID].userReadySprite.setVisible(true);
                    }
                }
            }else{
                this.readyBtn.setVisible(false);
            }
        }

        this.renew_dnxb();
        this.renew_ui();
        this.reloadAvatar();
    },
    //上桌
    OnSubSit : function(uid,seat,room_id,score,nickname,gender,avatar,ip)   {

        if(uid == dwc.Myself.GetData().GetUid())
        {
            this.mRoomID = room_id;
            this.mChairID = seat;
        }else{
            cc.audioEngine.playEffect("res/mj4/sound/sit.wav",false);
        }

        if(this.vecUser == undefined)
        {
            this.vecUser = [null,null,null,null];
        }
        if(seat < 4)
        {
            if(this.vecUser[seat] == undefined)
            {
                this.vecUser[seat] = {};
            }
            this.vecUser[seat].uid = uid;
            this.vecUser[seat].seat = seat;
            this.vecUser[seat].score = score;
            this.vecUser[seat].nickname = nickname;
            this.vecUser[seat].gender = gender;
            this.vecUser[seat].avatar = avatar;
            this.vecUser[seat].state = 0;
            this.vecUser[seat].ip = ip;
            this.vecUser[seat].offline = false;

            var wViewChairID=this.SwitchViewChairID(seat);
            this.userList[wViewChairID].userOfflineSprite.setVisible(this.vecUser[seat].offline);

            var cntUser = 0;
            for(var i=0;i<4;i++)
            {
                if (this.vecUser && this.vecUser[i] && this.vecUser[i].uid > 0)
                {
                    cntUser++;
                }
            }
            if(this.m_bGameStarted)
            {
                if(cntUser>= 4)
                {
                    this.inviteBtn.setVisible(false);
                    this.readyBtn.setVisible(false);
                }else{
                    this.inviteBtn.setVisible(false);
                    this.readyBtn.setVisible(false);
                }
            }else{
                if(cntUser>= 4)
                {
                    this.inviteBtn.setVisible(false);
                    if(this.vecUser[this.mChairID].state != US_READY)
                    {
                        this.readyBtn.setVisible(true);
                    }
                    for(var k=0;k<4;k++)
                    {
                        var wViewChairID=this.SwitchViewChairID(k);
                        if(this.vecUser[k].state == US_READY)
                        {
                            this.userList[wViewChairID].userReadySprite.setVisible(true);
                        }
                    }
                }else{
                    this.inviteBtn.setVisible(true);
                    this.readyBtn.setVisible(false);
                }
            }
            this.renew_ui();
            this.reloadAvatar();
        }else{
            cc.log("OnSubSit error seat : " + seat);
        }
    },
    //退出桌子
    OnSubStandUp : function(uid)   {

        if(this.vecUser) {
            for (var i = 0; i < this.vecUser.length; i++) {
                var wViewChairID = this.SwitchViewChairID(i);
                if (this.vecUser && this.vecUser[i] && this.vecUser[i].uid == uid) {
                    if (this.m_bTableStarted )
                    {
                        this.vecUser[i].offline = true;
                        this.userList[wViewChairID].userOfflineSprite.setVisible(this.vecUser[i].offline);
                    }else
                    {
                        this.vecUser[i].uid = 0;
                        this.vecUser[i].seat = 0;
                        this.vecUser[i].score = 0;
                        this.vecUser[i].nickname = "";
                        this.vecUser[i].gender = 0;
                        this.vecUser[i].avatar = 0;
                        this.vecUser[i].state = 0;
                        this.vecUser[i].ip = "0.0.0.0";
                        this.vecUser[i].offline = false;


                        this.userList[wViewChairID].userInfoBG.setVisible(false);
                        if(this.userList[wViewChairID].userHeadImg.getChildByTag(999)) {
                            this.userList[wViewChairID].userHeadImg.removeChildByTag(999, true);
                        }
                    }
                }
            }
        }

        if(uid == dwc.Myself.GetData().GetUid())
        {
            if(this.vecUser) {
                for (var i = 0; i < this.vecUser.length; i++) {
                    if (this.vecUser && this.vecUser[i]) {
                        this.vecUser[i].uid = 0;
                        this.vecUser[i].seat = 0;
                        this.vecUser[i].score = 0;
                        this.vecUser[i].nickname = "";
                        this.vecUser[i].gender = 0;
                        this.vecUser[i].avatar = 0;
                        this.vecUser[i].state = 0;
                        this.vecUser[i].offline = false;
                        this.vecUser[i].ip = "0.0.0.0";
                        var wViewChairID = this.SwitchViewChairID(i);
                        this.userList[wViewChairID].userInfoBG.setVisible(false);
                        if(this.userList[wViewChairID].userHeadImg.getChildByTag(999)) {
                            this.userList[wViewChairID].userHeadImg.removeChildByTag(999, true);
                        }
                    }
                }
            }

            this.RepositTable();

        }
        if (this.m_bTableStarted || this.mChairID == 0)
        {

        }else{
            dwc.Myself.SetMyRoom(null);
        }
    },
    OnSubKick : function(uid)   {
        if(this.vecUser)
        {
            if(uid == dwc.Myself.GetData().GetUid())
            {
                var pScene = new dwc.DT_MainScene();
                cc.director.runScene(pScene);

                var msgAlert=new dwc.PopupAlert("由于超过3局未准备，您被踢出房间");
                pScene.addChild(msgAlert);
                msgAlert.Show();
            }else{
                for(var i=0;i<this.vecUser.length;i++) {
                    if (this.vecUser && this.vecUser[i] && this.vecUser[i].uid == uid) {
                        this.vecUser[i].uid=0;
                        this.vecUser[i].seat=0;
                        this.vecUser[i].score=0;
                        this.vecUser[i].nickname="";
                        this.vecUser[i].gender=0;
                        this.vecUser[i].avatar=0;
                        this.vecUser[i].state=0;
                        this.vecUser[i].ip = "0.0.0.0";
                        var wViewChairID=this.SwitchViewChairID(i);
                        this.userList[wViewChairID].userInfoBG.setVisible(false);
                        if(this.userList[wViewChairID].userHeadImg.getChildByTag(999)) {
                            this.userList[wViewChairID].userHeadImg.removeChildByTag(999, true);
                        }
                    }
                }
            }
        }
    },
    OnSubReady : function(uid,seat)
    {
        var wViewChairID=this.SwitchViewChairID(seat);
        if(wViewChairID == 0 || wViewChairID == 2)
        {
            cc.audioEngine.playEffect("res/mj4/sound/woman_ready.mp3",false);
        }else{
            cc.audioEngine.playEffect("res/mj4/sound/man_ready.mp3",false);
        }
        if(seat < 4) {
            if (this.vecUser && this.vecUser[seat]) {
                this.vecUser[seat].state = US_READY;
            }
        }
        if(this.m_bGameStarted == false)
        {
            if(wViewChairID == 0)
            {
                this.readyBtn.setVisible(false);
            }
        }
        for(var i=0;i<4;i++)
        {
            var wViewChairID=this.SwitchViewChairID(i);
            if(this.vecUser[i].state == US_READY)
            {
                this.userList[wViewChairID].userReadySprite.setVisible(true);
            }else{
                this.userList[wViewChairID].userReadySprite.setVisible(false);
            }
        }
    },
    //发牌
    OnSubFaPai : function()   {
        var that = this;
        this.m_bTableStarted = true;
        this.m_bGameStarted = true;


        var pos=[cc.p(66,230),cc.p(1220,490),cc.p(970,648),cc.p(66,490)];
        for(var i=0;i<4;i++){
            this.userList[i].userInfoBG.setPosition(pos[i]);
            this.userList[i].userReadySprite.setVisible(false);
        }
        cc.audioEngine.playEffect("res/mj4/sound/game_start.mp3",false);

        this.readyBtn.setVisible(false);
        this.inviteBtn.setVisible(false);

        this.nodeFeng.setVisible(true);
        this.lefttimeLabel.setVisible(true);
        this.nodeRound.setVisible(true);


        this.chatBtn.setVisible(true);

        this.voiceBtn.setVisible(true);

        for(var i =0;i<4;i++) {
            for (var j = 0; j < 14; j++) {
                this.m_vecHandCard[i][j].setVisible(true);
                if(j == 14-1)
                {
                    this.m_vecHandCard[i][j].setVisible(false);
                }
                if(i == 0)
                {
                    this.m_vecHandCard[i][j].setStandPai(that.GetMajSide(0).Maj[j]);
                    this.m_vecHandCard[i][j].enableCheckBox(false);
                }
            }
        }
        this.renew_dnxb();
        this.renew_ui();
        this.renew_hand_pai();

        this.checkHandMj();
        //csmj.MJ_Data.SendMoPai();
    },

    OnSubMoPai : function(reason,bySeatID,byMj,opRight,byHandMj)
    {
        var that = this;

        var wViewChairID=that.SwitchViewChairID(bySeatID);
        this.hideOperatorBar();

        this.onMoPaiPaiAnimation(wViewChairID);
        for (var j = 0; j < 14; j++) {
            that.m_vecHandCard[0][j].enableCheckBox(false);
        }
        this.OnUserTouchMj(wViewChairID,byMj,byHandMj);

        this.reset_left_time();
        this.setCurrentFeng(wViewChairID);
        this.m_CurrentUser = wViewChairID;
        this.m_opRight = [0,0,0,0,0,0];
        if(wViewChairID == 0)
        {
            this.m_opRight = opRight;

            this.m_bQiaoXiangHu = opRight[6];

            //this.scheduleOnce(function(){
                that.renew_mopai();
            //},0.2);
        }else{
            this.scheduleOnce(function(){
                var pCard = that.m_vecHandCard[wViewChairID][14-1];
                pCard.setVisible(true);
            },0.3);
        }
        this.checkHandMj();
    },
    renew_mopai : function()
    {
        var that = this;

        for (var j = 0; j < 14; j++) {
            that.m_vecHandCard[0][j].reset_position();
        }

        this.checkHandMj();
        var bGang = this.m_opRight[2];
        var bTing = this.m_opRight[3];
        var bHu = this.m_opRight[4];

        var lMajSide = that.GetMajSide(0);
        var byMj = lMajSide.GetMoPai();
        var pCard = that.m_vecHandCard[0][14-1];
        pCard.setStandPai(byMj);
        this.renew_hand_pai();
        this.renew_chi_pai();
        this.renew_tingxuan();
        if (this.m_byTing[0]  == 0)
        {
            if (bHu || bGang || bTing)
            {
                that.showOperatorBar(false,false,bGang,bTing,bHu,true);
            }
        }else{
            if (bHu)
            {
                that.showOperatorBar(false,false,false,false,bHu,true);
            }else{
                this.scheduleOnce(function()
                {
                    that.ChuPai(byMj);
                },0.4);
            }
        }
        cc.audioEngine.playEffect("res/mj4/sound/mopai.wav",false);
    },
    //--------------------------------------------------------------
    //用户出牌
    OnUserOutMj : function(  wViewChairID,  byOutMj ,byHandMj){

        var that = this;
        var l_MajSide = that.GetMajSide(wViewChairID);
        var byHandMjCount = l_MajSide.GetHandMjCount();
        if(byHandMjCount % 3 == 2)
        {
            if (wViewChairID == 0)
            {
                if(byHandMj)
                {
                    l_MajSide.ChuPai(byOutMj);
                    for( var byIndex=0; byIndex<14; byIndex++ )
                    {
                        //有效删除麻将
                        l_MajSide.Maj[byIndex] = byHandMj[byIndex];
                    }
                    this.SortCard(l_MajSide.Maj,14,this.m_vecGuiPai);
                }else{
                    for( var byIndex=0; byIndex<14; byIndex++ )
                    {
                        if( l_MajSide.Maj[byIndex] == byOutMj )
                        {
                            //有效删除麻将
                            l_MajSide.Maj[byIndex] = 255;
                            l_MajSide.ChuPai(byOutMj);
                            this.SortCard(l_MajSide.Maj,14,this.m_vecGuiPai);
                            break;
                        }
                    }
                }
            }else{
                //有效删除麻将
                //l_MajSide.Maj[14-1] = 255;

                //有效删除麻将
                var cntBlock = l_MajSide.GetBlockCount();
                for( var i=0; i<14; i++ )
                {
                    if(i<13-cntBlock*3)
                    {
                        l_MajSide.Maj[i] = 42;
                    }else{
                        l_MajSide.Maj[i] = 255;
                    }
                }

                l_MajSide.ChuPai(byOutMj);
            }
        }

        //return false;
    },
    //用户摸牌
    OnUserTouchMj : function(  wViewChairID,byMj,byHandMj){
        var that = this;
        var l_MajSide = that.GetMajSide(wViewChairID);
        l_MajSide.Maj[14-1] = byMj;
        if(byHandMj)
        {
            for( var byIndex=0; byIndex<14; byIndex++ )
            {
                //有效删除麻将
                l_MajSide.Maj[byIndex] = byHandMj[byIndex];
            }
            this.SortCard(l_MajSide.Maj,13,this.m_vecGuiPai);
        }
    },

    OnAfterOutMj : function(  wViewChairID,bIsChi,bIsPeng,bIsGang,bHu)
    {

    },
//用户碰牌
    OnUserPeng : function(  byViewSeatID,byMj,block,byHandMj)
    {
        var that = this;

        var l_MajSide = that.GetMajSide(byViewSeatID);

        l_MajSide.Peng(byMj,block,byHandMj);

        this.SortCard(l_MajSide.Maj,13,this.m_vecGuiPai);

        var l_CurMajSide = that.GetMajSide(this.m_CurrentUser);
        l_CurMajSide.BeiChiPai();
    },
//用户吃牌//吃牌类型,0-无,1-@@*, 2-@*@, 3-*@@
    OnUserChi : function(  byViewSeatID, byMj,	nChiType,block,byHandMj)
    {
        var that = this;

        var l_MajSide = that.GetMajSide(byViewSeatID);


        l_MajSide.Chi(byMj,nChiType,block,byHandMj);

        this.SortCard(l_MajSide.Maj,13,this.m_vecGuiPai);


        var l_CurMajSide = that.GetMajSide(this.m_CurrentUser);
        l_CurMajSide.BeiChiPai();
    },
//用户杠牌//杠牌类型,0-无, 1-明杠,2-补杠, 4-暗杠//所杠的牌，自摸可以有多种杠牌的可能
    OnUserGang : function(  byViewSeatID,	byGangMj,nGangMode,block,byHandMj)
    {
        var that = this;

        var l_MajSide = that.GetMajSide(byViewSeatID);

        l_MajSide.Gang(byGangMj,nGangMode,block,byHandMj);

        //l_MajSide.SortCard();
        //l_MajSide.Maj[12] = l_MajSide.Maj[13];
        //l_MajSide.Maj[13] = 255;
        this.SortCard(l_MajSide.Maj,13,this.m_vecGuiPai);

        if (nGangMode == 1)
        {
            var l_CurMajSide = that.GetMajSide(this.m_CurrentUser);
            l_CurMajSide.BeiChiPai();
        }
    },
//用户听牌
    OnUserTing : function(  byViewSeatID)
    {
        var that = this;
        this.m_byTing[byViewSeatID] = 1;
    },
//用户吃牌
    OnUserHu : function( byWinnerSeatID,byFangQiangSeatID,byMj)
    {
        var that = this;

        mj4.MajLogic.m_byHu[byWinnerSeatID] ++;
        var l_WinnerMajSide = that.GetMajSide(byWinnerSeatID);
        l_WinnerMajSide.Hu(byMj,byFangQiangSeatID);
        l_WinnerMajSide.SetMoPai(byMj);

        if(byFangQiangSeatID < 4) {
            var l_FangQiangMajSide = that.GetMajSide(byFangQiangSeatID);
            l_FangQiangMajSide.BeiHuPai(byMj);
        }
    },
    renew_kehupai : function()
    {

        var that = this;
        var l_MajSide = this.GetMajSide(0);
        var MJTestObj = new csmj_MJTest();
        var byKeHuPai = MJTestObj.GetKeHuPai(l_MajSide.Maj);
        if(byKeHuPai.length > 0)
        {
            this.nodeKeHuPai.setVisible(true);
            for(var i = 0 ;i < 13;i++)
            {
                this.m_vecKeHuCard[i].setVisible(false);
            }
            for(var i = 0 ;i < byKeHuPai.length;i++) {
                this.m_vecKeHuCard[i].setStandPai(byKeHuPai[i]);
                this.m_vecKeHuCard[i].setVisible(true);
            }
        }else{
            this.nodeKeHuPai.setVisible(false);
        }
        this.nodeKeHuPai.setVisible(false);
    },
    reset_tingxuan : function()
    {
        for(var i = 0 ;i < 14;i++)
        {
            this.m_vecHandCard[0][i].setTingXuanVisible(false);
        }
    },
    renew_tingxuan : function()
    {
        if(true)
        {
            return;
        }
        if(this.m_byTing[0] == 0)
        {
            var that = this;
            var l_MajSide = this.GetMajSide(0);
            var MJTestObj = new csmj_MJTest();
            var byTingXuanPai = MJTestObj.GetTingXuan(l_MajSide.Maj,l_MajSide.block);
            if(byTingXuanPai.length > 0)
            {
                var byHandLieCount = l_MajSide.GetBlockCount()*3;
                for(var i = 0 ;i < 14;i++) {
                    that.m_vecHandCard[0][i].setTingXuanVisible(false);
                }
                for(var i = 0 ;i < 14;i++)
                {
                    if(l_MajSide.Maj[i] < 42)
                    {
                        var pos = i+byHandLieCount;
                        for(var k =0;k< byTingXuanPai.length;k++)
                        {
                            if(i == 13)
                            {
                                pos = 13;
                            }
                            if(pos < 14)
                            {
                                if(l_MajSide.Maj[i] == byTingXuanPai[k])
                                {
                                    that.m_vecHandCard[0][pos].setTingXuanVisible(true);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    showTanPai : function(tanpai)
    {
        try
        {
            for(var i=1;i<4;i++)
            {
                var seat = this.SwitchRealChairID(i);
                var vecPai = tanpai[seat*2];
                var vecHu = tanpai[seat*2+1];
                var cntBlockCount = 0;
                for(var j=0;j<4;j++)
                {
                    if(vecHu[j*2+1] > 0)
                    {
                        cntBlockCount++;
                    }
                }
                for(var k = 0 ;k < 14;k++)
                {
                    if(vecPai[k]<=42) {
                        var pngStr1 = this.getPaiRes(i, vecPai[k]);
                        this.m_vecHandCard[i][k + cntBlockCount * 3].initWithSpriteFrameName(pngStr1);
                        this.m_vecHandCard[i][k + cntBlockCount * 3].setVisible(true);
                        if (i == 2) {
                            this.m_vecHandCard[i][k + cntBlockCount * 3].scale = 0.76;
                        } else {
                            this.m_vecHandCard[i][k + cntBlockCount * 3].scale = 1.05;
                        }
                    }
                }
            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }

    },
    getPaiRes : function(seat,mjPai)
    {
        var type=parseInt(mjPai / 9);
        var index=mjPai - type*9;
        var picseat = seat;
        if(picseat == 0)
        {
            picseat = 2;
        }

        var pngStr=picseat +"_" +(type*10+index+1)+".png";
        return pngStr;
    },


    //bySeatID,byMj,byKeHuPai
    OnSubChuPai: function (bySeatID,byMj,opRight,byTing,byHandMj) {
        var that = this;
        var wViewChairID=that.SwitchViewChairID(bySeatID);

        this.hideOperatorBar();
        //this.setCurrentFeng(255);
        this.reset_tingxuan();


        if(wViewChairID == 0 || wViewChairID == 2)
        {
            cc.audioEngine.playEffect("res/mj4/sound/pai/female/"+byMj+".mp3",false);
        }else{
            cc.audioEngine.playEffect("res/mj4/sound/pai/male/"+byMj+".mp3",false);
        }

        mj4.MajLogic.SetLastOutMj(byMj);

        this.OnUserOutMj(wViewChairID,byMj,byHandMj);

        this.m_CurrentUser = wViewChairID;

        that.currentSprite.setPosition(cc.p(1500,1500));
        that.currentSprite.setVisible(false);

        var factor = 1;
        if(that.m_byTing[0] > 0)
        {
            factor = 0.8;
        }

        if(wViewChairID == 0) {
            for(var i=1;i<4;i++)
            {
                var lMajSide = that.GetMajSide(i);
                lMajSide.SetMoPai(255);
                that.m_vecHandCard[i][14-1].setVisible(false);
            }
            that.checkHandMj();
            that.scheduleOnce(function() {


                for(var i=0;i<13;i++)
                {
                    that.m_vecHandCard[0][i].setDotVisible(false);
                }

                that.m_vecHandCard[0][14-1].setStandPai(255);
                that.renew_kehupai();
                for (var i = 0; i < 14; i++) {
                    that.m_vecHandCard[0][i].reset_position();
                }
                if(that.m_byTing[0] > 0)
                {
                    that.m_vecFourOutCard[wViewChairID].setStandPai(byMj);
                    that.m_vecFourOutCard[wViewChairID].runAction(cc.sequence(cc.show(),cc.delayTime(0.3 * factor),cc.callFunc(function () {
                        that.m_vecFourOutCard[wViewChairID].setStandPai(255);

                        var byOutMjCount = mj4.MajLogic.GetOutMjCount(wViewChairID);
                        if(byOutMjCount>0 && byOutMjCount <= that.m_vecOutCard[wViewChairID].length)
                        {
                            if(that.m_vecOutCard[wViewChairID][byOutMjCount-1] == undefined)
                            {
                                that.m_vecOutCard[wViewChairID][byOutMjCount-1] = undefined;
                            }else{
                                that.m_vecOutCard[wViewChairID][byOutMjCount-1].setLiePai(byMj);
                                that.m_vecOutCard[wViewChairID][byOutMjCount-1].setVisible(true);
                                that.m_vecOutCard[wViewChairID][byOutMjCount-1].showCurrent(that.currentSprite);
                            }
                        }

                        //test 测试显示下一个人发的牌
                        that.renew_ui();
                        that.renew_table();
                        cc.audioEngine.playEffect("res/mj4/sound/dapai.wav",false);
                        //test  end
                    },that)));
                }else {
                    var byOutMjCount = mj4.MajLogic.GetOutMjCount(wViewChairID);
                    if (byOutMjCount > 0 && byOutMjCount <= that.m_vecOutCard[wViewChairID].length) {
                        if (that.m_vecOutCard[wViewChairID][byOutMjCount - 1] == undefined) {
                            that.m_vecOutCard[wViewChairID][byOutMjCount - 1] = undefined;
                        } else {
                            that.m_vecOutCard[wViewChairID][byOutMjCount - 1].setLiePai(byMj);
                            that.m_vecOutCard[wViewChairID][byOutMjCount - 1].setVisible(true);
                            that.m_vecOutCard[wViewChairID][byOutMjCount - 1].showCurrent(that.currentSprite);
                        }
                    }
                }

                //test 测试显示下一个人发的牌
                that.renew_ui();
                that.renew_table();
                that.renew_hand_pai();
                cc.audioEngine.playEffect("res/mj4/sound/dapai.wav", false);
            },0.25*factor);
        }else{
            for(var i=1;i<4;i++)
            {
                var lMajSide = that.GetMajSide(i);
                lMajSide.SetMoPai(255);
                that.m_vecHandCard[i][14-1].setVisible(false);
            }
            that.scheduleOnce(function(){
                that.m_vecHandCard[wViewChairID][14-1].setVisible(false);

                if (that.m_byTing[0] == 0) {
                    if (opRight[0] || opRight[1] || opRight[2] || opRight[4]) {
                        this.showOperatorBar(opRight[0], opRight[1], opRight[2], opRight[3], opRight[4], opRight[5]);
                    }
                } else {
                    if (opRight[4]) {
                        //this.showOperatorBar(false, false, false, false, true, true);
                        that.hideOperatorBar();
                        csmj.MJ_Data.SendHuPai();
                    }else{
                        if (opRight[0] || opRight[1] || opRight[2] ) {
                            csmj.MJ_Data.SendGuoPai();
                        }
                    }
                }
                that.m_vecFourOutCard[wViewChairID].setStandPai(byMj);
                that.m_vecFourOutCard[wViewChairID].runAction(cc.sequence(cc.show(),cc.delayTime(0.3*factor),cc.callFunc(function () {
                    that.m_vecFourOutCard[wViewChairID].setStandPai(255);

                    var byOutMjCount = mj4.MajLogic.GetOutMjCount(wViewChairID);
                    if(byOutMjCount>0 && byOutMjCount <= that.m_vecOutCard[wViewChairID].length)
                    {
                        if(that.m_vecOutCard[wViewChairID][byOutMjCount-1] == undefined)
                        {
                            that.m_vecOutCard[wViewChairID][byOutMjCount-1] = undefined;
                        }else{
                            that.m_vecOutCard[wViewChairID][byOutMjCount-1].setLiePai(byMj);
                            that.m_vecOutCard[wViewChairID][byOutMjCount-1].setVisible(true);
                            that.m_vecOutCard[wViewChairID][byOutMjCount-1].showCurrent(that.currentSprite);
                        }
                    }

                    //test 测试显示下一个人发的牌
                    that.renew_ui();
                    that.renew_table();
                    cc.audioEngine.playEffect("res/mj4/sound/dapai.wav",false);
                    //test  end
                },that)));
            },0.2);
        }
    },
    OnSubChiPai : function(bySeatID,byOutMjSeatID,byChiMj,block,byChiMode,byTingRight,byHandMj){
        var that = this;
        var wViewChairID=that.SwitchViewChairID(bySeatID);
        var wViewOutChairID=that.SwitchViewChairID(byOutMjSeatID);
        for(var i=0;i<4;i++)
        {
            if(this.m_vecChiSide[wViewChairID][i] == 255)
            {
                this.m_vecChiSide[wViewChairID][i] = wViewOutChairID;
                break;
            }
        }

        this.hideOperatorBar();
        this.currentSprite.setPosition(cc.p(1500,1500));
        this.currentSprite.setVisible(false);

        that.playChiEffect(wViewChairID);

        this.OnUserChi(wViewChairID,byChiMj,byChiMode,block,byHandMj);
        that.renew_table();
        that.renew_hand_pai();
        this.renew_chi_pai();
        that.renew_tingxuan();

        this.checkHandMj();

        this.m_CurrentUser = wViewChairID;

        this.m_waitState = "STATE_NULL";
    },
    OnSubPengPai : function(bySeatID,byOutMjSeatID,byChiMj,block,byChiMode,byTingRight,byHandMj){
        var that = this;
        var wViewChairID=that.SwitchViewChairID(bySeatID);
        var wViewOutChairID=that.SwitchViewChairID(byOutMjSeatID);
        for(var i=0;i<4;i++)
        {
            if(this.m_vecChiSide[wViewChairID][i] == 255)
            {
                this.m_vecChiSide[wViewChairID][i] = wViewOutChairID;
                break;
            }
        }
        this.hideOperatorBar();
        this.currentSprite.setPosition(cc.p(1500,1500));
        this.currentSprite.setVisible(false);

        that.playPengEffect(wViewChairID);

        this.OnUserPeng(wViewChairID,byChiMj,block,byHandMj);

        this.m_CurrentUser = wViewChairID;

        that.renew_table();
        that.renew_hand_pai();
        that.renew_chi_pai();
        that.renew_tingxuan();
        that.checkHandMj();
        that.m_waitState = "STATE_NULL";
    },
    OnSubGangPai : function(bySeatID,byOutMjSeatID,byGangMj,block,byGangMode,byBuMj,bTing,vecHu,bZiMoGang,byHandMj)
    {
        var that = this;
        var wViewChairID=that.SwitchViewChairID(bySeatID);
        var wViewOutChairID=that.SwitchViewChairID(byOutMjSeatID);
        for(var i=0;i<4;i++)
        {
            if(this.m_vecChiSide[wViewChairID][i] == 255)
            {
                this.m_vecChiSide[wViewChairID][i] = wViewOutChairID;
                break;
            }
        }
        this.hideOperatorBar();
        this.currentSprite.setPosition(cc.p(1500,1500));
        this.currentSprite.setVisible(false);

        that.playGangEffect(wViewChairID);


        this.OnUserGang(wViewChairID,byGangMj,byGangMode,block,byHandMj);

        that.renew_table();
        that.renew_hand_pai();
        that.renew_chi_pai();
        that.renew_tingxuan();

        that.checkHandMj();

        that.m_waitState = "STATE_NULL";

        var fTingTimeFactor = 1.0;
        //if (this.m_byTing[0]) {
            //fTingTimeFactor = 0.8;
        //}

        this.m_CurrentUser = wViewChairID;
        if(vecHu[this.mChairID])
        {
            this.showOperatorBar(false,false,false,false,true,true);
        }
    },
    OnSubHuPai : function(byWinner,byFangQiang,byMj,winScore,winResultScore)
    {
        this.m_bGameStarted = false;
        var that = this;
        that.m_waitState = "STATE_HU";
        var winnerViewChairID = this.SwitchViewChairID(byWinner);
        var fangqiangViewChairID = 255;
        if(byFangQiang < 4)
        {
            fangqiangViewChairID = this.SwitchViewChairID(byFangQiang);
        }else{
            fangqiangViewChairID = winnerViewChairID;
        }

        this.OnUserHu(winnerViewChairID,fangqiangViewChairID,byMj);

        this.setCurrentFeng(winnerViewChairID);

        this.currentSprite.setPosition(cc.p(1500,1500));
        this.currentSprite.setVisible(false);

        if(byWinner != this.mChairID) {
            that.playHuEffect(winnerViewChairID);
        }
        this.checkHandMj();
            //that.ChuPai()


        if(byFangQiang < 4)
        {
            if(winnerViewChairID == 0 || winnerViewChairID == 2)
                {
                    var nowTime = new Date().getTime();
                    cc.audioEngine.playEffect("res/mj4/sound/pai/girl/hu_"+Math.ceil(nowTime%3)+".mp3",false);
                }else{
                    var nowTime = new Date().getTime();
                    cc.audioEngine.playEffect("res/mj4/sound/pai/boy/hu_"+Math.ceil(nowTime%3)+".mp3",false);
                }

            for(var i=0;i<4;i++)
            {
                if(winScore[i] != 0)
                {
                    var wViewChairID = this.SwitchViewChairID(i);
                    this.showWinScoreEffect(wViewChairID,"dianpao",winScore[i]);
                }
            }
        }else
        {
            if(winnerViewChairID == 0 || winnerViewChairID == 2)
                {
                    var nowTime = new Date().getTime();
                    cc.audioEngine.playEffect("res/mj4/sound/pai/girl/zimo_"+Math.ceil(nowTime%3)+".mp3",false);
                }else{
                    var nowTime = new Date().getTime();
                    cc.audioEngine.playEffect("res/mj4/sound/pai/boy/zimo_"+Math.ceil(nowTime%3)+".mp3",false);
                }

            for(var i=0;i<4;i++)
            {
                if(winScore[i] != 0)
                {
                    var wViewChairID = this.SwitchViewChairID(i);
                    this.showWinScoreEffect(wViewChairID,"zimo",winScore[i]);
                }
            }
        }
        //this.showWinScoreEffect();
        for(var i=0;i<4;i++)
        {
            this.vecUser[i].score += winScore[i];
            this.m_vecRoundWinScore[i] = winResultScore[i];
        }

        for(var i = 0;i<4;i++)
        {
                var wViewChairID = this.SwitchViewChairID(i);
                if (this.vecUser[i] && this.vecUser[i].uid > 0) {
                    this.userList[wViewChairID].userScore.setString(""+this.vecUser[i].score);
                    this.userList[wViewChairID].winScore.setString(winResultScore[i]);
                }
        }
        //that.renew_hand_pai();

        this.renew_table();


        this.m_CurrentUser = winnerViewChairID;
        this.renew_ui();
        this.renew_hand_pai();
        this.renew_chi_pai();


    },
    OnSubMoMa : function(vecMaPai) {
        this.isNeedMoMa = true;
        this.vecMaPai = [];
        this.vecZhongMa = [];

        var cntMaPai = 0;
        for (var i = 0; i < vecMaPai.length; i++) {
            if (vecMaPai[i] >= 0 && vecMaPai[i] < 42) {
                this.vecMaPai[cntMaPai] = vecMaPai[i];
                cntMaPai++;
            }
        }
        var cntZhongMa = 0;
        for (var i = 0; i < this.vecMaPai.length; i++) {
            var byMj = this.vecMaPai[i];
            if (this.mChairID == 0 && (byMj == 0 || byMj == 4 || byMj == 8 || byMj == 27)) {
                this.vecZhongMa[cntZhongMa] = byMj;
                cntZhongMa++;
            }
            if (this.mChairID == 1 && (byMj == 1 || byMj == 5 || byMj == 31 || byMj == 28)) {
                this.vecZhongMa[cntZhongMa] = byMj;
                cntZhongMa++;
            }
            if (this.mChairID == 2 && (byMj == 2 || byMj == 6 || byMj == 32 || byMj == 29)) {
                this.vecZhongMa[cntZhongMa] = byMj;
                cntZhongMa++;
            }
            if (this.mChairID == 3 && (byMj == 3 || byMj == 7 || byMj == 33 || byMj == 30)) {
                this.vecZhongMa[cntZhongMa] = byMj;
                cntZhongMa++;
            }
        }
        this.cntMaxMaPai = cntMaPai;

        var that = this;

        that.scheduleOnce(function () {
            that.m_waitState = "STATE_MOMA";
            that.onMaPaiAnimation();
        }, 2.0);

    },

    OnSubJieSuan : function(byRound,byZhuang,byLianZhuang,userJieSuan0,userJieSuan1,userJieSuan2,userJieSuan3){
        var that = this;
        this.hideOperatorBar();
        for(var i=0;i<4;i++) {
            if (this.vecUser && this.vecUser[i])
            {
                this.vecUser[i].state = US_NULL;
            }
        }
        var report = [];
        report[0] = userJieSuan0;
        report[1] = userJieSuan1;
        report[2] = userJieSuan2;
        report[3] = userJieSuan3;

        /*
        for(var i=0;i<4;i++)
        {
            var wViewChairID = this.SwitchViewChairID(i);
            this.jiesuanList[wViewChairID].nicknameLabel.setString(report[i].nickname);
            this.jiesuanList[wViewChairID].winScoreLabel.setString(report[i].winScore);
            this.jiesuanList[wViewChairID].loseScoreLabel.setString(report[i].loseScore);
            this.jiesuanList[wViewChairID].roundScoreLabel.setString(report[i].roundScore);
        }
        */

        var tanpai =  [[8,18,19,21,23,25,26,255,255,255,255,255,255,255],[255,3,22,6,20,0,255,0,255],
            [2,4,5,10,10,12,17,19,21,23,24,24,26,255],[255,0,255,0,255,0,255,0,255],
            [0,1,3,7,8,10,11,11,15,17,18,25,25,255],[255,0,255,0,255,0,255,0,255],
            [0,2,6,6,9,9,9,14,16,17,19,25,26,255],[255,0,255,0,255,0,255,0,255]];

        for(var i=0;i<4;i++)
        {
            var lMajSide = that.GetMajSide(i);
            for(var j=0;j<14;j++)
            {
                //lMajSide.Maj[j] = report[i].vecHandMj[j];
                tanpai[i*2+0][j] = report[i].vecHandMj[j];
            }
            for(var k=0;k<9;k++)
            {
                //lMajSide.block[k][0] = report[i].hu[k*2+1];
                //lMajSide.block[k][1] = report[i].hu[k*2+2];
                tanpai[i*2+1][k] = report[i].hu[k];
            }
        }

        that.tanpai = tanpai;
        that.renew_ui();
        that.jiesuanParam = this.roomDesc;
        that.jiesuanReport = report;
        that.jiesuanZhuang = byZhuang;


        this.scheduleOnce(function () {

            that.m_waitState = "STATE_JIESUAN";
            that.showJieSuan();

        },2.0);

    },
    showJieSuan : function()
    {
        var that = this;
        that.m_waitState = "STATE_JIESUAN";

        //test end

            that.inviteBtn.setVisible(false);
            that.readyBtn.setVisible(false);

            //that.nodeJieSuan.setVisible(true);
            //that.nodeJieSuanBG.setVisible(true);
            //that.foldBtn.setVisible(false);
            //that.spreadBtn.setVisible(false);
            //that.againBtn.setVisible(false);

            if(that.m_nRound == that.m_nMaxRound)
            {
                csmj.JieSuanReportDialog.showReport(this.jiesuanReport,that.jiesuanZhuang,true,that.jiesuanParam,this.m_vecGuiPai);
            }else{
                csmj.JieSuanReportDialog.showReport(this.jiesuanReport,that.jiesuanZhuang,false,that.jiesuanParam,this.m_vecGuiPai);
            }
            that.foldBtn.setVisible(true);
            that.spreadBtn.setVisible(false);
            that.nodeJieSuanBG.setVisible(true);
            that.showTanPai(that.tanpai);

    },
    _checkFinalReport : function(dt)
    {
        if(this.final_report)
        {
            this.unschedule(this._checkFinalReport);
            var dlg=new csmj.FinalReportDialog(this);
            //this.target.addChild(dlg,999);
            this.addChild(dlg,999);
            dlg.showReport(this.final_report);
            this.final_report = null;
        }
    },
    OnSubFinalReport : function(cbReason,userReport0,userReport1,userReport2,userReport3)
    {
        var that = this;

        /*
        var report = [];
        var obj = {};
        obj.nickname = "xxxx";
        obj.uid = "xxxx";
        obj.score = 85;
        obj.zimo = 1;
        obj.hu = 6;
        obj.win = 1;
        obj.lose = 1;

        report[0] = obj;
        report[1] = obj;
        report[2] = obj;
        report[3] = obj;
        */
        var report = [];
        report[0] = userReport0;
        report[1] = userReport1;
        report[2] = userReport2;
        report[3] = userReport3;
        that.final_report = report;
        if(cbReason == 4)
        {
            dwc.Myself.SetMyRoom(null);
            var dlg=new csmj.FinalReportDialog(this.target);
            //this.target.addChild(dlg,999);
            this.addChild(dlg,999);
            dlg.showReport(this.final_report);
            this.final_report = null;
        }
        this.againBtn.setVisible(false);
        this.reportBtn.setVisible(true);
    },
    GetMeChairID : function()//坐标映射
    {
        return this.mChairID;
    },
    SwitchViewChairID : function( wChairID )//坐标映射
    {
        //转换椅子
        var wViewChairID=Math.abs(wChairID+4-this.GetMeChairID());

        return wViewChairID % 4;
    },
    SwitchRealChairID : function( wChairID )//坐标映射
    {
        //转换椅子
        var wRealChairID=this.GetMeChairID() + wChairID;

        return wRealChairID % 4;
    },
    VecStr2Int : function(vec){
        var result = [];
        if(vec == undefined)
        {
            cc.log("undefined");
        }
        for(var i = 0;i<vec.length;i++)
        {
            result[i] = parseInt(vec[i])
        }
        return result;
    },
    OnWebSocketMessage: function (_msg) {
        //hu_mode : 0,没胡,1自摸,2放枪
        var that = this;
        var vecArg = _msg.mjmsg.split("|");
        if (vecArg[0] == "joinroom") {
            var uid = parseInt(vecArg[1]);
            var cbResult = parseInt(vecArg[2]);
            var room_id = parseInt(vecArg[3]);
            var maxRound = parseInt(vecArg[4]);
            var vecParam =  this.VecStr2Int(vecArg[5].split(","));
            var game_name = vecArg[6];

            this.mRoomID = room_id;
            this.m_nMaxRound = maxRound;

            this.fjhLabel.setString("房号 "+this.mRoomID + "  "+ game_name);

            //this.OnSubJoinRoom(uid);
        }
        else if (vecArg[0] == "leave") {
            var uid = parseInt(vecArg[1]);

            this.OnSubLeave(uid);
        }else if (vecArg[0] == "online") {
            var uid = parseInt(vecArg[1]);
            var seat = parseInt(vecArg[2]);

            if(seat < 4)
            {
                this.userList[seat].userOfflineSprite.setVisible(false);
            }
            //this.OnSubOffline(uid);
        }else if (vecArg[0] == "offline") {
            var uid = parseInt(vecArg[1]);
            var seat = parseInt(vecArg[2]);

            if(seat < 4)
            {
                this.userList[seat].userOfflineSprite.setVisible(true);
            }
            //this.OnSubOffline(uid);
        }else if (vecArg[0] == "try_dismissroom") {
            var uid = parseInt(vecArg[1]);
            var nickname = vecArg[2];
            var room_id = parseInt(vecArg[3]);

            if(uid != dwc.Myself.GetData().GetUid())
            {
                that.suredismissLayout.setVisible(true);
                that.suredismissLayoutContent = $.getNodeByName(that.mainNode,"ID_LABEL_SUREDISMISS_CONTENT");
                that.suredismissLayoutContent.setString("玩家【"+nickname+"】请求解散房间,\n是否确认解散");
            }
        }else if (vecArg[0] == "cancel_dismissroom") {
            var uid = parseInt(vecArg[1]);
            var nickname = vecArg[2];
            var room_id = parseInt(vecArg[3]);

            if(uid != dwc.Myself.GetData().GetUid())
            {
                that.dismissLayout.setVisible(false);
                that.suredismissLayout.setVisible(false);
            }
        }else if (vecArg[0] == "agree_dismissroom") {
            var uid = parseInt(vecArg[1]);
            var nickname = vecArg[2];
            var room_id = parseInt(vecArg[3]);

        }else if (vecArg[0] == "refuse_dismissroom") {
            var uid = parseInt(vecArg[1]);
            var nickname = vecArg[2];
            var room_id = parseInt(vecArg[3]);
            if(uid != dwc.Myself.GetData().GetUid()) {
                var alert = new dwc.PopupAlert("玩家【" + nickname + "】拒绝解散房间，继续游戏。");
                $.runningScene.addChild(alert, 1000);
                alert.Show();

                that.dismissLayout.setVisible(false);
                that.suredismissLayout.setVisible(false);
            }
        }else if (vecArg[0] == "dismissroom") {
            var uid = parseInt(vecArg[1]);
            dwc.Myself.SetMyRoom(null);
            cc.director.runScene(new dwc.DT_MainScene());

        }else if (vecArg[0] == "param")
        {
            this.roomDesc = vecArg[3];//总的是否开始
            this.renew_param();
        }
        else if (vecArg[0] == "table")
        {
            this.mRoomID = parseInt(vecArg[1]);//总的是否开始
            this.m_bTableStarted = parseInt(vecArg[2]);//是否开始
            this.m_byYuPai = parseInt(vecArg[3]);//
            this.m_nRound = parseInt(vecArg[4]);//
            this.m_nMaxRound = parseInt(vecArg[5]);//房间ID
            this.m_bGameStarted = parseInt(vecArg[6]);//玩家
            this.m_cntLookon = parseInt(vecArg[7]);//观众

            this.fjhLabel.setString("房号 "+this.mRoomID);



            var vecSeatInfo = [];
            vecSeatInfo.push(vecArg[8]);vecSeatInfo.push(vecArg[9]);vecSeatInfo.push(vecArg[10]);vecSeatInfo.push(vecArg[11])

            var userInfoList = [];
            for(var i =0;i<4;i++)
            {
                var seatInfo = vecSeatInfo[i];
                var user=seatInfo.split("#");
                var userInfo={};

                userInfo.uid=parseInt(user[0]);
                userInfo.seat=parseInt(user[1]);
                userInfo.score=parseInt(user[2]);
                userInfo.nickname=user[3];
                userInfo.diFen=parseInt(user[4]);
                userInfo.gender=parseInt(user[5]);
                userInfo.avatar=parseInt(user[6]);
                userInfo.state=parseInt(user[7]);
                userInfo.vip=parseInt(user[8]);
                userInfo.title=parseInt(user[9]);
                userInfo.lookon=parseInt(user[10]);
                userInfo.ip=user[11];
                userInfoList.push(userInfo);
            }
            this.OnSubTable(userInfoList);
        }else if (vecArg[0] == "table_begin")
        {

            this.m_bTableStarted = true;
            this.m_bGameStarted = true;
            var byParam = this.VecStr2Int(vecArg[1].split(","));
            var byZhuang = parseInt(vecArg[2]);
            var byRound = parseInt(vecArg[3]);
            var byMaxRound = parseInt(vecArg[4]);
            var byYuPai = parseInt(vecArg[5]);
            var byCurrentUser = parseInt(vecArg[6]);
            var lScore = this.VecStr2Int(vecArg[7].split(","));
            var lRoundScore = this.VecStr2Int(vecArg[8].split(","));

            var byLastOutMj = parseInt(vecArg[9]);

            var vecGuiPai = this.VecStr2Int(vecArg[10].split(","));

            var cntGuiPai = 0;
            this.m_vecGuiPai = [];
            for(var i=0;i<vecGuiPai.length;i++)
            {
                if(vecGuiPai[i] >= 0 && vecGuiPai[i] < 42)
                {
                    this.m_vecGuiPai.push(vecGuiPai[i]);
                    cntGuiPai++;
                }
            }

            this.m_byYuPai = byYuPai;
            this.m_byZhuang = byZhuang;
            this.m_nRound = byRound;
            this.m_nMaxRound = byMaxRound;
            this.m_CurrentUser = this.SwitchViewChairID(byCurrentUser);
            this.setCurrentFeng(this.m_CurrentUser);

            for(var i =0;i<4;i++)
            {
                if(this.vecUser[i])
                {
                    this.vecUser[i].score = lScore[i];
                    this.m_vecRoundWinScore[i] = lRoundScore[i];
                }
            }
            mj4.MajLogic.SetLastOutMj(byLastOutMj);
            if(!this.guiMJ0 && vecGuiPai[0] < 42)
            {
                var mjPai = vecGuiPai[0];
                var type=parseInt(mjPai / 9);
                var index=mjPai - type*9;

                var pngStr="#m_"+(type*10+index+1)+".png";

                this.guiMJ0 =  new cc.Sprite(pngStr);
                this.guiMJ0.setPosition(90,612);
                this.guiMJ0.setScale(0.6);
                this.nodeMyHandMj.addChild(this.guiMJ0);
            }


            //this.OnSubTableBegin();
        }else if (vecArg[0] == "table_side")
        {
            var bySeatID = parseInt(vecArg[1]);
            var byTing = parseInt(vecArg[2]);
            var Maj =this.VecStr2Int(vecArg[3].split(","));
            var Hua = this.VecStr2Int(vecArg[4].split(","));
            var hu = this.VecStr2Int(vecArg[5].split(","));
            var outMj = this.VecStr2Int(vecArg[6].split(","));
            var opRight = this.VecStr2Int(vecArg[7].split(","));

            if(bySeatID < 4)
            {
                var wViewChairID = this.SwitchViewChairID(bySeatID);
                var lMajSide = that.GetMajSide(wViewChairID);

                for(var i=0;i<14;i++)
                {
                    lMajSide.Maj[i] = Maj[i];
                }
                for(var i=0;i<4;i++)
                {
                    lMajSide.block[i] = [hu[i*2+1],hu[i*2+2]];
                }
                for(var i=0;i<20;i++)
                {
                    lMajSide.outMj[i] = outMj[i];
                }

                this.SortCard(lMajSide.Maj,13,this.m_vecGuiPai);
                this.m_byTing[wViewChairID] = byTing;
                if(wViewChairID == 0) {
                    this.m_opRight = opRight;

                    var bChi = opRight[0];
                    var bPeng = opRight[1];
                    var bGang = opRight[2];
                    var bTing = opRight[3];
                    var bHu = opRight[4];

                    if (this.m_byTing[0]  == 0)
                    {
                        if (bChi || bPeng || bHu || bGang || bTing)
                        {
                            that.showOperatorBar(bChi,bPeng,bGang,bTing,bHu,true);
                        }
                    }else{
                        if (bHu)
                        {
                            csmj.MJ_Data.SendHuPai();
                        }else
                        {
                            this.scheduleOnce(function()
                            {
                                var lMajSide = that.GetMajSide(0);
                                for(var i=14-1;i>=0;i--)
                                {
                                    if(lMajSide.Maj[i] < 42)
                                    {
                                        that.ChuPai(lMajSide.Maj[i]);
                                        break;
                                    }
                                }
                            },0.6);
                        }
                    }
                }
            }
            //this.OnSubTableBegin();
        }else if (vecArg[0] == "table_end")
        {
            //this.showOperatorBar(false,false,true,false,false,true);
            if(this.vecUser && this.vecUser[seat])
            {
                this.vecUser[seat].state = US_PLAY;
            }

            this.m_bGameStarted = true;

            var pos=[cc.p(66,230),cc.p(1220,490),cc.p(970,648),cc.p(66,490)];
            for(var i=0;i<4;i++){
                this.userList[i].userInfoBG.setPosition(pos[i]);
                this.userList[i].userReadySprite.setVisible(false);
            }

            this.readyBtn.setVisible(false);
            this.inviteBtn.setVisible(false);

            this.nodeFeng.setVisible(true);
            this.lefttimeLabel.setVisible(true);
            this.nodeRound.setVisible(true);


            this.chatBtn.setVisible(true);

            this.voiceBtn.setVisible(true);


            if(this.m_bGameStarted == true && this.GetMajSide(0).Maj[0] != 255)
            {
                for (var j = 0; j < 14; j++)
                {
                    this.m_vecHandCard[0][j].setVisible(true);
                    if(j == 14-1)
                    {
                        //this.m_vecHandCard[0][j].setVisible(false);
                    }

                    this.m_vecHandCard[0][j].setStandPai(that.GetMajSide(0).Maj[j]);
                    this.m_vecHandCard[0][j].enableCheckBox(false);
                }
            }

            this.renew_ui();
            this.renew_dnxb();
            this.renew_table();
            this.renew_hand_pai();
            this.renew_chi_pai();

            //this.OnSubTableEnd();
        }else if (vecArg[0] == "yupai") {
            this.m_byYuPai = parseInt(vecArg[1]);//
            this.leftpaiLabel.setString(""+this.m_byYuPai);
            if(this.m_byYuPai == 4)
            {
                this.OnShowHint("剩余最后四张牌",2);
            }
        }else if (vecArg[0] == "status_free") {

        }else if (vecArg[0] == "status_play") {

        }else if (vecArg[0] == "sit") {
            //test///////////////////////////////////////////
            var uid = parseInt(vecArg[1]);
            var seat = parseInt(vecArg[2]);
            var room_id = parseInt(vecArg[3]);
            var score = parseInt(vecArg[4]);
            var nickname = vecArg[5];
            var gender = parseInt(vecArg[6]);
            var avatar = parseInt(vecArg[7]);
            var ip = (vecArg[8]);

            //this.fjhLabel.setString("房号 "+this.mRoomID);

            this.OnSubSit(uid,seat,room_id,score,nickname,gender,avatar,ip);

        }
        else if (vecArg[0] == "standup") {
            var uid = parseInt(vecArg[1]);

            this.OnSubStandUp(uid);
        }
        else if (vecArg[0] == "kick") {
            var uid = parseInt(vecArg[1]);

            this.OnSubKick(uid);
        }
        else if (vecArg[0] == "ready") {
            var uid = parseInt(vecArg[1]);
            var seat = parseInt(vecArg[2]);

            this.OnSubReady(uid,seat);
        }

        else if (vecArg[0] == "roomuser") {

        }
        else if (vecArg[0] == "fapai")
        {
            var byRound = parseInt(vecArg[1]);
            var byZhuang = parseInt(vecArg[2]);
            var byLianZhuang = parseInt(vecArg[3]);
            var byMaxRound = parseInt(vecArg[4]);
            var Maj0 = this.VecStr2Int(vecArg[5].split(","));
            var vecGuiPai = this.VecStr2Int(vecArg[6].split(","));

            this.m_nRound = byRound;
            this.m_nMaxRound = byMaxRound;
            mj4.MajLogic.m_byZhuang = byZhuang;
            var cntGuiPai = 0;
            this.m_vecGuiPai = [];
            for(var i=0;i<vecGuiPai.length;i++)
            {
                if(vecGuiPai[i] >= 0 && vecGuiPai[i] < 42)
                {
                    this.m_vecGuiPai.push(vecGuiPai[i]);
                    cntGuiPai++;
                }
            }
            mj4.MajLogic.SetGuiPai(this.m_vecGuiPai);


            var l_MajSide = that.GetMajSide(0);
            l_MajSide.Maj =  Maj0;//mj4.MajLogic.SortCard(Maj0,14);

            this.SortCard(l_MajSide.Maj,14,this.m_vecGuiPai);
            for(var i=1;i<4;i++)
            {
                that.GetMajSide(i).Maj = [0,0,0,0,0,0,0,0,0,0,0,0,0,255];
            }
            this.OnSubFaPai();
            if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
            {
                this.onGuiPaiAnimation(this.m_vecGuiPai);
            }

        }else if (vecArg[0] == "mopai")
        {
            //摸牌:  mopai|reason|bySeatID|byMj|0,0,bGang,bTing,bHu
            var reason = parseInt(vecArg[1]);
            var bySeatID = parseInt(vecArg[2]);
            var byMj = parseInt(vecArg[3]);
            var opRight = this.VecStr2Int(vecArg[4].split(","));
            var byHandMj= this.VecStr2Int(vecArg[5].split(","));

            this.OnSubMoPai(reason,bySeatID,byMj,opRight,byHandMj);
        }else if (vecArg[0] == "chupai")
        {
            //出牌:  chupai|bySeatID|byMj|opRight|byTingPos|byKeHuPai
            var bySeatID = parseInt(vecArg[1]);
            var byMj = parseInt(vecArg[2]);
            var opRight= this.VecStr2Int(vecArg[3].split(","));
            var byTingPos  = parseInt(vecArg[4]);
            var byHandMj= this.VecStr2Int(vecArg[5].split(","));

            this.OnSubChuPai(bySeatID,byMj,opRight,byTingPos,byHandMj);
        }else if (vecArg[0] == "chipai")
        {
            //吃牌:  chipai|bySeatID|byOutMjSeatID|byChiMj|block.style,block.first|byChiMode|byTingRight|byHandMj
            var bySeatID = parseInt(vecArg[1]);
            var byOutMjSeatID = parseInt(vecArg[2]);
            var byChiMj = parseInt(vecArg[3]);
            var block  = this.VecStr2Int(vecArg[4].split(","));
            var byChiMode = parseInt(vecArg[5]);
            var byTingRight  = parseInt(vecArg[6]);
            var byHandMj  = this.VecStr2Int(vecArg[7].split(","));
            this.OnSubChiPai(bySeatID,byOutMjSeatID,byChiMj,block,byChiMode,byTingRight,byHandMj);
        }else if (vecArg[0] == "pengpai")
        {
            //吃牌:  chipai|bySeatID|byChiMj|block.style,block.first|byChiMode|byTing|byHandMj
            var bySeatID = parseInt(vecArg[1]);
            var byOutMjSeatID = parseInt(vecArg[2]);
            var byChiMj = parseInt(vecArg[3]);
            var block  = this.VecStr2Int(vecArg[4].split(","));
            var byChiMode = parseInt(vecArg[5]);
            var byTingRight  = parseInt(vecArg[6]);
            var byHandMj  = this.VecStr2Int(vecArg[7].split(","));
            this.OnSubPengPai(bySeatID,byOutMjSeatID,byChiMj,block,byChiMode,byTingRight,byHandMj);
        }else if (vecArg[0] == "gangpai")
        {
            //杠牌:  gangpai|bySeatID|byGangMj|byGangMode|byBuMj|byAddBaoPai|opRight|byHandMj
            var bySeatID = parseInt(vecArg[1]);
            var byOutMjSeatID = parseInt(vecArg[2]);
            var byChiMj = parseInt(vecArg[3]);
            var block  = this.VecStr2Int(vecArg[4].split(","));
            var byGangMode = parseInt(vecArg[5]);
            var byBuMj = parseInt(vecArg[6]);
            var bTing = parseInt(vecArg[7]);
            var vecHu  = this.VecStr2Int(vecArg[8].split(","));
            var bZiMoGang = parseInt(vecArg[8]);
            var byHandMj  = this.VecStr2Int(vecArg[10].split(","));
            this.OnSubGangPai(bySeatID,byOutMjSeatID,byChiMj,block,byGangMode,byBuMj,bTing,vecHu,bZiMoGang,byHandMj);
        }else if (vecArg[0] == "hupai")
        {
            //胡牌:  hupai|bySeatID|hu_mode
            var byWinner = parseInt(vecArg[1]);
            var byFangQiang = parseInt(vecArg[2]);
            var byHuMj = parseInt(vecArg[3]);
            var winScore  = this.VecStr2Int(vecArg[4].split(","));
            var winResultScore  = this.VecStr2Int(vecArg[5].split(","));

            this.OnSubHuPai(byWinner,byFangQiang,byHuMj,winScore,winResultScore);
        }else if (vecArg[0] == "moma")
        {
            //胡牌:
            var vecMaPai  = this.VecStr2Int(vecArg[1].split(","));


            this.OnSubMoMa(vecMaPai);
        }else if (vecArg[0] == "jiesuan")
        {
            var byRound = parseInt(vecArg[1]);
            var byZhuang = parseInt(vecArg[2]);
            var byLianZhuang = parseInt(vecArg[3]);
            var getJieSuanObj = function(data)
            {
                var vecData = data.split("#");
                var obj = {};
                obj.roundScore = parseInt(vecData[0]);
                obj.huType = vecData[1];
                obj.vecHandMj = that.VecStr2Int(vecData[2].split(","));
                obj.hu = that.VecStr2Int(vecData[3].split(","));
                return obj;
            };
            var userJieSuan0 = getJieSuanObj(vecArg[4]);
            var userJieSuan1 = getJieSuanObj(vecArg[5]);
            var userJieSuan2 = getJieSuanObj(vecArg[6]);
            var userJieSuan3 = getJieSuanObj(vecArg[7]);

            userJieSuan0.uid = this.vecUser[0].uid;
            userJieSuan1.uid = this.vecUser[1].uid;
            userJieSuan2.uid = this.vecUser[2].uid;
            userJieSuan3.uid = this.vecUser[3].uid;

            userJieSuan0.nickname = this.vecUser[0].nickname;
            userJieSuan1.nickname = this.vecUser[1].nickname;
            userJieSuan2.nickname = this.vecUser[2].nickname;
            userJieSuan3.nickname = this.vecUser[3].nickname;
            
            this.OnSubJieSuan(byRound,byZhuang,byLianZhuang,userJieSuan0,userJieSuan1,userJieSuan2,userJieSuan3);
        }else if (vecArg[0] == "avatar")
        {
            var uid = parseInt(vecArg[1]);
            var avatar_url = (vecArg[2]);
            //avatar_url = "http://wx.qlogo.cn/mmopen/JNACPtSVg5xBbL3KdUaL3ticM0WiaQzMoIWEY4pyKtMQ19aqFsLWurU8JayNtd7RZmxhe3ibLAlkwbDakZUXI6RqQ/0";
            for(var i = 0 ;i<4;i++)
            {
                if(this.vecUser[i] && this.vecUser[i].uid == uid)
                {
                    this.vecUser[i].avatar_url = avatar_url;
                    break;
                }
            }
            this.reloadAvatar();
        }else if (vecArg[0] == "report")
        {
            var getReportObj = function(data)
            {
                var vecData = data.split("#");
                var obj = {};
                obj.uid = parseInt(vecData[0]);
                obj.cntZiMo = parseInt(vecData[1]);
                obj.cntHu = parseInt(vecData[2]);
                obj.cntDianPao = parseInt(vecData[3]);
                obj.cntGang = parseInt(vecData[4]);
                obj.winScore = parseInt(vecData[5]);
                obj.loseScore = parseInt(vecData[6]);
                obj.resultScore = parseInt(vecData[7]);
                return obj;
            };
            var cbReason = vecArg[1];
            var cbType = vecArg[2];
            var userReport0 = getReportObj(vecArg[3]);
            var userReport1 = getReportObj(vecArg[4]);
            var userReport2 = getReportObj(vecArg[5]);
            var userReport3 = getReportObj(vecArg[6]);

            userReport0.uid = this.vecUser[0].uid;
            userReport1.uid = this.vecUser[1].uid;
            userReport2.uid = this.vecUser[2].uid;
            userReport3.uid = this.vecUser[3].uid;

            userReport0.nickname = this.vecUser[0].nickname;
            userReport1.nickname = this.vecUser[1].nickname;
            userReport2.nickname = this.vecUser[2].nickname;
            userReport3.nickname = this.vecUser[3].nickname;

            userReport0.avatar_url = this.vecUser[0].avatar_url;
            userReport1.avatar_url = this.vecUser[1].avatar_url;
            userReport2.avatar_url = this.vecUser[2].avatar_url;
            userReport3.avatar_url = this.vecUser[3].avatar_url;

            this.OnSubFinalReport(cbReason,userReport0,userReport1,userReport2,userReport3);
        }else if (vecArg[0] == "voice") {
            cc.log("来语音了",_msg);
            var uid = parseInt(vecArg[1]);
            var seat = parseInt(vecArg[2]);
            var seconds=parseInt(vecArg[3]);
            var url=vecArg[4];
            this.OnSubVoice(uid,seat,seconds,url);

            //this.OnPlayVoice(seconds,url);
        }else if (vecArg[0] == "yuyin") {
            cc.log("来语音了",_msg);
            var uid = parseInt(vecArg[1]);
            var seat = parseInt(vecArg[2]);
            var index = parseInt(vecArg[3]);

            this.OnSubYuYin(uid,seat,index);
        }else if (vecArg[0] == "biaoqing") {
            var uid = parseInt(vecArg[1]);
            var seat = parseInt(vecArg[2]);
            var index = parseInt(vecArg[3]);

            this.OnSubBiaoQing(uid,seat,index);
        }else if (vecArg[0] == "text") { //新增普通消息////////////////////////
            var uid = parseInt(vecArg[1]);
            var seat = parseInt(vecArg[2]);
            var content = vecArg[3];
            this.OnSubChatTextMsg(uid,seat,content);
        }
    },
});
csmj.JieSuanReportDialog= {
    init : function(mainNode){
        var that = this;
        var rootNode = $.getNodeByName(mainNode,"ID_NODE_JIESUAN");
        rootNode.setVisible(false);
        this.rootNode = rootNode;

        this.spBG = $.getNodeByName(rootNode,"ID_NODE_JIESUANBG");

        this.spResult = $.getNodeByName(rootNode,"ID_SPRITE_JS_RESULT");


        this.vecNickLabel = [];
        this.vecNickLabel[0] = $.getNodeByName(rootNode,"ID_LABEL_JS_NICK0");
        this.vecNickLabel[1] = $.getNodeByName(rootNode,"ID_LABEL_JS_NICK1");
        this.vecNickLabel[2] = $.getNodeByName(rootNode,"ID_LABEL_JS_NICK2");
        this.vecNickLabel[3] = $.getNodeByName(rootNode,"ID_LABEL_JS_NICK3");


        this.vecHuTypeLabel = [];
        this.vecHuTypeLabel[0] = $.getNodeByName(rootNode,"ID_LABEL_JS_HUTYPE0");
        this.vecHuTypeLabel[1] = $.getNodeByName(rootNode,"ID_LABEL_JS_HUTYPE1");
        this.vecHuTypeLabel[2] = $.getNodeByName(rootNode,"ID_LABEL_JS_HUTYPE2");
        this.vecHuTypeLabel[3] = $.getNodeByName(rootNode,"ID_LABEL_JS_HUTYPE3");

        this.vecScoreLabel = [];
        this.vecScoreLabel[0] = $.getNodeByName(rootNode,"ID_LABEL_JS_SCORE0");
        this.vecScoreLabel[1] = $.getNodeByName(rootNode,"ID_LABEL_JS_SCORE1");
        this.vecScoreLabel[2] = $.getNodeByName(rootNode,"ID_LABEL_JS_SCORE2");
        this.vecScoreLabel[3] = $.getNodeByName(rootNode,"ID_LABEL_JS_SCORE3");

        this.vecRoundScoreLabel = [];
        this.vecRoundScoreLabel[0] = $.getNodeByName(rootNode,"ID_LABEL_JS_WINSCORE0");
        this.vecRoundScoreLabel[1] = $.getNodeByName(rootNode,"ID_LABEL_JS_WINSCORE1");
        this.vecRoundScoreLabel[2] = $.getNodeByName(rootNode,"ID_LABEL_JS_WINSCORE2");
        this.vecRoundScoreLabel[3] = $.getNodeByName(rootNode,"ID_LABEL_JS_WINSCORE3");

        this.vecHuSprite = [];
        this.vecHuSprite[0] = $.getNodeByName(rootNode,"ID_SPRITE_JS_HU0");
        this.vecHuSprite[1] = $.getNodeByName(rootNode,"ID_SPRITE_JS_HU1");
        this.vecHuSprite[2] = $.getNodeByName(rootNode,"ID_SPRITE_JS_HU2");
        this.vecHuSprite[3] = $.getNodeByName(rootNode,"ID_SPRITE_JS_HU3");


        this.vecZhuangSprite = [];
        this.vecZhuangSprite[0] = $.getNodeByName(rootNode,"ID_SPRITE_JS_ZHUANG0");
        this.vecZhuangSprite[1] = $.getNodeByName(rootNode,"ID_SPRITE_JS_ZHUANG1");
        this.vecZhuangSprite[2] = $.getNodeByName(rootNode,"ID_SPRITE_JS_ZHUANG2");
        this.vecZhuangSprite[3] = $.getNodeByName(rootNode,"ID_SPRITE_JS_ZHUANG3");


        for(var i=0;i<4;i++)
        {
            this.vecHuSprite[i].setVisible(false);
            this.vecZhuangSprite[i].setVisible(false);
        }
        this.vecJieSuanCard = [];
    },
    showReport : function(report,byZhuang,isEnd,param,vecGuiPai)
    {
        var that = this;
        this.rootNode.setVisible(true);
        if(vecGuiPai == undefined || vecGuiPai == null)
        {
            vecGuiPai = [];
        }
        this.m_vecGuiPai = vecGuiPai;
        /*
        if(isEnd)
        {
            this.closeBtn.setVisible(false);
            this.finalReportBtn.setVisible(true);
        }else{
            this.closeBtn.setVisible(true);
            this.finalReportBtn.setVisible(false);
        }
        */

        try
        {
            for(var i = 0 ;i < this.vecJieSuanCard.length;i++)
            {
                var card = this.vecJieSuanCard[i];
                card.removeFromParent();
            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
        try
        {
            if(this.guiMJ0)
            {
                this.guiMJ0.removeFromParent();
                this.guiMJ0 = null;
            }
            if(this.m_vecGuiPai && this.m_vecGuiPai[0])
            {
                var mjPai = this.m_vecGuiPai[0];
                var type=parseInt(mjPai / 9);
                var index=mjPai - type*9;

                var pngStr="#m_"+(type*10+index+1)+".png";

                this.guiMJ0 =  new cc.Sprite(pngStr);
                this.guiMJ0.setScale(0.6);
                this.guiMJ0.setPosition(200,664);
                this.spBG.addChild(this.guiMJ0);
            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
        this.vecJieSuanCard = [];

        for(var i=0;i<4;i++) {
            if (report[i] && report[i].uid == dwc.Myself.GetData().GetUid() && report[i].roundScore > 0) {
                this.spResult.initWithSpriteFrameName("win_title.png");
                cc.audioEngine.playEffect("res/mj4/sound/win.mp3");
                break;
            }else if (report[i] && report[i].uid == dwc.Myself.GetData().GetUid() && report[i].roundScore < 0) {
                this.spResult.initWithSpriteFrameName("lose_title.png");
                cc.audioEngine.playEffect("res/mj4/sound/lost.mp3");
                break;
            }else if (report[i] && report[i].uid == dwc.Myself.GetData().GetUid()) {
                this.spResult.initWithSpriteFrameName("daping_title.png");
                cc.audioEngine.playEffect("res/mj4/sound/audio_liuju.mp3");
                break;
            }
        }

        var zhuangUid = 0;

        if(report[byZhuang])
        {
            zhuangUid = report[byZhuang].uid;
        }
        var reportOrder = [];
        for(var i=0;i<4;i++)
        {
            if (report[i] && report[i].uid && report[i].uid == dwc.Myself.GetData().GetUid())
            {
                reportOrder.push(report[i]);
            }
        }
        for(var i=0;i<4;i++)
        {
            if (report[i] && report[i].uid && report[i].uid != dwc.Myself.GetData().GetUid())
            {
                reportOrder.push(report[i]);
            }
        }
        report = reportOrder;
        for(var i=0;i<4;i++)
        {
            if(report[i] && report[i].nickname)
            {
                this.vecNickLabel[i].setString(report[i].nickname);
            }
            if(report[i] && report[i].uid == zhuangUid)
            {
                this.vecZhuangSprite[i].setVisible(true);
            }else{
                this.vecZhuangSprite[i].setVisible(false);
            }

            this.vecHuTypeLabel[i].setString(report[i].huType );
            if(report[i].roundScore> 0)
            {
                this.vecScoreLabel[i].setString("+" + report[i].roundScore );
            }
            if(report[i].roundScore< 0)
            {
                this.vecScoreLabel[i].setString(report[i].roundScore );
            }
            if(report[i].roundScore== 0)
            {
                this.vecScoreLabel[i].setString(report[i].roundScore );
            }
        }

        var block = [];
        for(var i=0;i<4;i++)
        {
            var offset = 150;
            var vecHandMj = report[i].vecHandMj;

            var hu = report[i].hu;
            for(var k =0; k < 4; k++)
            {
                var bIsBlock = true;
                var kBlock = [];

                var byBlockMj = [255,255,255,255];

                kBlock[0] = hu[k*2+1];
                kBlock[1] =  hu[k*2+2];
                switch (kBlock[0]) {
                    case 1: // BLOCK_CHI = 1
                        byBlockMj[0] = kBlock[1];
                        byBlockMj[1] = kBlock[1] + 1;
                        byBlockMj[2] = kBlock[1] + 2;
                        byBlockMj[3] = 255;

                        break;
                    case 3: // BLOCK_PENG = 3
                        byBlockMj[0] = kBlock[1];
                        byBlockMj[1] = kBlock[1];
                        byBlockMj[2] = kBlock[1];
                        byBlockMj[3] = 255;
                        break;
                    case 5: // BLOCK_GANG = 5
                        byBlockMj[0] = kBlock[1];
                        byBlockMj[1] = kBlock[1];
                        byBlockMj[2] = kBlock[1];
                        byBlockMj[3] = kBlock[1];
                        break;
                    case 6: // BLOCK_AN_GANG
                        byBlockMj[0] = kBlock[1];
                        byBlockMj[1] = kBlock[1];
                        byBlockMj[2] = kBlock[1];
                        byBlockMj[3] = kBlock[1];
                        break;
                    default:
                    {
                        bIsBlock = false;
                    }
                        break;
                }

                if(this.m_vecGuiPai && this.m_vecGuiPai[0] < 42)
                {
                    for(var j=0;j<4;j++)
                    {
                        if(byBlockMj[j] == this.m_vecGuiPai[0])
                        {
                            byBlockMj[j] = 33;
                        }
                    }
                }

                if (bIsBlock)
                {
                    var card1 = new mj4.OUT_CARD(0,byBlockMj[0],0.86);
                    card1.setPosition(cc.p(offset, 520-120*i));
                    card1.setGuiPai(this.m_vecGuiPai,"res/mj4/zjmj/gui_icon.png");
                    this.spBG.addChild(card1, 3);
                    this.vecJieSuanCard.push(card1);
                    offset += 44;
                    var card2 = new mj4.OUT_CARD(0,byBlockMj[1],0.86);
                    card2.setPosition(cc.p(offset, 520-120*i));
                    card1.setGuiPai(this.m_vecGuiPai,"res/mj4/zjmj/gui_icon.png");
                    this.spBG.addChild(card2, 3);
                    this.vecJieSuanCard.push(card2);
                    offset += 44;
                    var card3 = new mj4.OUT_CARD(0,byBlockMj[2],0.86);
                    card1.setGuiPai(this.m_vecGuiPai,"res/mj4/zjmj/gui_icon.png");
                    card3.setPosition(cc.p(offset, 520-120*i));
                    this.spBG.addChild(card3, 3);
                    this.vecJieSuanCard.push(card3);
                    offset += 44;

                    if(byBlockMj[3] != 255)
                    {
                        var card4 = new mj4.OUT_CARD(0,byBlockMj[3],0.86);
                        card4.setPosition(cc.p(offset, 520-120*i));
                        card1.setGuiPai(this.m_vecGuiPai,"res/mj4/zjmj/gui_icon.png");
                        this.spBG.addChild(card4, 3);
                        this.vecJieSuanCard.push(card4);
                        offset += 44;
                    }
                    offset += 30;
                }else{
                    break;
                }
            }
            this.SortCard(vecHandMj,13);
            for(var k=0;k<13;k++)
            {
                if(vecHandMj[k]!= 255){
                    var card1 = new mj4.OUT_CARD(0,vecHandMj[k],0.86);
                    card1.setPosition(cc.p(offset, 520-120*i));
                    card1.setGuiPai(this.m_vecGuiPai,"res/mj4/zjmj/gui_icon.png");
                    this.spBG.addChild(card1, 3);
                    this.vecJieSuanCard.push(card1);
                    offset += 44;
                }else{
                    break;
                }
            }
            if(vecHandMj[13] != 255)
            {
                offset += 44;
                var card1 = new mj4.OUT_CARD(0,vecHandMj[13],0.86);
                card1.setPosition(cc.p(offset, 520-120*i));
                card1.setGuiPai(this.m_vecGuiPai,"res/mj4/zjmj/gui_icon.png");
                this.spBG.addChild(card1, 3);
                this.vecJieSuanCard.push(card1);
            }
        }
    },
    SortCard: function (byHandCard,byHandMjCount)// static void SortCard(BYTE byHandCard[],BYTE byHandMjCount);
    {
        if(byHandMjCount === undefined)
        {
            byHandMjCount = 13;
        }
        for(var i = 0;i < byHandMjCount - 1;i++)
        {
            for(var j = i;j < byHandMjCount;j++)
            {
                if(this.m_vecGuiPai)
                {
                    if(this.m_vecGuiPai.indexOf(byHandCard[j]) >= 0)
                    {
                        if(this.m_vecGuiPai.indexOf(byHandCard[i]) < 0) {
                            var tempValue = byHandCard[i];
                            byHandCard[i] = byHandCard[j];
                            byHandCard[j] = tempValue;
                        }
                    }else if(this.m_vecGuiPai.indexOf(byHandCard[i]) < 0 && byHandCard[i] > byHandCard[j])
                    {
                        var tempValue = byHandCard[i];
                        byHandCard[i] = byHandCard[j];
                        byHandCard[j] = tempValue;
                    }
                }else{
                    if(byHandCard[i] > byHandCard[j])
                    {
                        var tempValue = byHandCard[i];
                        byHandCard[i] = byHandCard[j];
                        byHandCard[j] = tempValue;
                    }
                }
            }
        }
        if(this.m_vecGuiPai && this.m_vecGuiPai.length > 0)
        {
            var cntBai = 0;
            var cntCS = 0;
            var vec1 = [];
            var vec2 = [];
            for (var i = 0; i < byHandMjCount; i++)
            {
                if(byHandCard[i] == 33 && byHandCard[i] != this.m_vecGuiPai[0]) {
                    cntBai++;
                }else{
                    if (byHandCard[i] < this.m_vecGuiPai[0])
                    {
                        vec1.push(byHandCard[i]);
                    }
                    if (byHandCard[i] > this.m_vecGuiPai[0])
                    {
                        vec2.push(byHandCard[i]);
                    }
                    if (byHandCard[i] == this.m_vecGuiPai[0])
                    {
                        cntCS++;
                    }
                }
            }
            for (var i = 0; i < byHandMjCount-cntCS; i++)
            {
                if(i<vec1.length)
                {
                    byHandCard[i+cntCS] = vec1[i];
                }
                if(i>=vec1.length && i<byHandMjCount-vec2.length)
                {
                    byHandCard[i+cntCS] = 33;
                }
                if(i>=vec1.length+cntBai)
                {
                    byHandCard[i+cntCS] = vec2[i-vec1.length-cntBai];
                }
            }
        }
        return byHandCard;
    },
};
csmj.FinalReportDialog=dwc.CommonAlertView.extend({
    ctor: function (target) {
        this._super();
        this.target = target;

        this.initUI(target);
        cc.audioEngine.playEffect("res/mj4/sound/final_report.mp3",false);
    },
    showReport : function(vecReport)
    {
        this.vecReport = vecReport;

        if(this.vecReport)
        {
            var bigwin_seat = 255;
            var bigwin_score = 0;
            for(var i=0;i<4;i++) {
                var report = this.vecReport[i];
                if(report.resultScore > bigwin_score)
                {
                    bigwin_seat = i;
                    bigwin_score = report.resultScore;
                }
                if(report.resultScore == bigwin_score)
                {
                    //bigwin_seat = 255;
                }
            }
            for(var i=0;i<4;i++)
            {
                var report = this.vecReport[i];
                var userReport = this.userReport[i];
                if(report && userReport)
                {
                    if(bigwin_seat == i)
                    {
                        var vecBigWinPos = [cc.p(263,221),cc.p(570,221),cc.p(861,221),cc.p(1212,221)];
                        userReport.spBigWin.setVisible(true);
                    }else{
                        userReport.spBigWin.setVisible(false);
                    }
                    userReport.nickLabel.setString(report.nickname);
                    userReport.idLabel.setString("ID:"+report.uid);
                    userReport.scoreLabel.setString(""+report.resultScore);


                    userReport.totalLabel0.setString("x" + report.cntHu);
                    userReport.totalLabel1.setString("x" + report.cntDianPao);
                    if(report.winScore > 0)
                    {
                        userReport.totalLabel2.setString("+" + report.winScore);
                    }else{
                        userReport.totalLabel2.setString("0");
                    }
                    if(report.loseScore < 0)
                    {
                        userReport.totalLabel3.setString("" + report.loseScore);
                    }else{
                        userReport.totalLabel3.setString("0");
                    }

                    if(report.avatar_url)
                    {
                        dwc.GX_UserHeadImgManager.GetUrlImg(report.avatar_url, function (target, success, sprite) {
                            var headImageSprite = sprite;
                            if (success) {
                                headImageSprite.setScale(target.width / headImageSprite.width, target.height / headImageSprite.height);
                                headImageSprite.setAnchorPoint(cc.p(0.5, 0.5));
                                headImageSprite.setPosition(cc.p(target.width / 2, target.height / 2));
                                target.addChild(headImageSprite, 0, 999);
                            } else {
                                cc.log("get img error");
                                headImageSprite = new cc.Sprite("res/image/OtherImages/default_avatar.png");

                                headImageSprite.setScale(target.width / headImageSprite.width, target.height / headImageSprite.height);
                                headImageSprite.setAnchorPoint(cc.p(0.5, 0.5));
                                headImageSprite.setPosition(cc.p(target.width / 2, target.height / 2));
                                target.addChild(headImageSprite, 0, 999);
                            }
                        }, userReport.userHeadImg);
                    }
                }
            }
        }
        this.Show();
    },
    initUI: function () {
        var that = this;
        var mainNode = ccs.load("res/MJ4_FinalReport.json").node;
        this.addChild(mainNode);

        var closeBtn=$.getNodeByName(mainNode,"ID_BUTTON_CLOSE");
        closeBtn.addClickEventListener(function () {
            that.Close();
            csmj.MJ_Data.SendDismissRoom();
            cc.audioEngine.stopAllEffects();
            cc.director.runScene(new dwc.DT_MainScene());
        });


        var shareBtn=$.getNodeByName(mainNode,"ID_BUTTON_SHARE");
        shareBtn.addClickEventListener(function () {
            that.OnClickWeChat();
        });
        var wechatBtn=$.getNodeByName(mainNode,"ID_BUTTON_WECHAT");
        wechatBtn.addClickEventListener(function () {
            that.OnClickWeChat();
        });

        var timelineBtn=$.getNodeByName(mainNode,"ID_BUTTON_TIMELINE");
        timelineBtn.addClickEventListener(function () {
            that.OnClickTimeLinet();
        });

        this.userReport = [];
        for(var i=0;i<4;i++)
        {
            var obj = {};
            obj.headLayout = $.getNodeByName(mainNode,"ID_LAYOUT_HEAD"+i);
            obj.userHeadImg = $.getNodeByName(mainNode,"ID_IMAGEVIEW_HEADIMAGE"+i);
            obj.nickLabel = $.getNodeByName(mainNode,"ID_LABEL_NICK"+i);
            obj.idLabel = $.getNodeByName(mainNode,"ID_LABEL_ID"+i);
            obj.scoreLabel = $.getNodeByName(mainNode,"ID_LABEL_SCORE"+i);

            obj.totalLabel0 = $.getNodeByName(mainNode,"ID_LABEL_TOTAL_"+i +"_0");
            obj.totalLabel1 = $.getNodeByName(mainNode,"ID_LABEL_TOTAL_"+i +"_1");
            obj.totalLabel2 = $.getNodeByName(mainNode,"ID_LABEL_TOTAL_"+i +"_2");
            obj.totalLabel3 = $.getNodeByName(mainNode,"ID_LABEL_TOTAL_"+i +"_3");

            obj.spBigWin = $.getNodeByName(mainNode,"ID_SPRITE_BIGWIN"+i);

            this.userReport.push(obj);
        }
    },
    reloadAvatar : function()
    {
        for(var i=0;i<4;i++)
        {
            var wViewChairID = this.SwitchViewChairID(i);
            if(this.vecUser[i] && this.vecUser[i].uid > 0 && this.vecUser[i].avatar_url)
            {
                this.userList[wViewChairID].uid = this.vecUser[i].uid;
                //test
                var avatar_url = this.vecUser[i].avatar_url;
                //avatar_url="http://img.cjpoker.com/csmj.png";
                //test end

                if (!this.userList[wViewChairID].userHeadImg.getChildByTag(999)) {
                    var param = {
                        avatar: this.vecUser[i].avatar,
                        gender: this.vecUser[i].gender,
                        avatar_url: avatar_url
                    };
                    dwc.GX_UserHeadImgManager.GetUrlImg(avatar_url, function (target, success, sprite, param) {
                        var headImageSprite = sprite;
                        if (success) {
                            headImageSprite.setScale(target.width / headImageSprite.width, target.height / headImageSprite.height);
                            headImageSprite.setAnchorPoint(cc.p(0.5, 0.5));
                            headImageSprite.setPosition(cc.p(target.width / 2, target.height / 2));
                            target.addChild(headImageSprite, 0, 999);
                        } else {
                            cc.log("get img error");
                            headImageSprite = new cc.Sprite("res/image/OtherImages/default_avatar.php");

                            headImageSprite.setScale(target.width / headImageSprite.width, target.height / headImageSprite.height);
                            headImageSprite.setAnchorPoint(cc.p(0.5, 0.5));
                            headImageSprite.setPosition(cc.p(target.width / 2, target.height / 2));
                            target.addChild(headImageSprite, 0, 999);
                        }
                    }, this.userList[wViewChairID].userHeadImg, param);
                }
            }
        }
    },
    OnClickWeChat : function()
    {
        try
        {
            var uid = dwc.Myself.GetData().GetUid();
            var now_time = new Date().getTime();
            var picName="" +now_time+".png";

            if (cc.sys.os == cc.sys.OS_ANDROID) {
                var fullPicName = jsb.fileUtils.getWritablePath() + "/" + picName;
                if (jsb.fileUtils.isFileExist(fullPicName))
                {
                    jsb.fileUtils.removeFile(fullPicName);
                }
                $.OnJiePing(picName);
                this.scheduleOnce(function(){
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "ShareToWeChatLocImg", "(Ljava/lang/String;)V", fullPicName);
                },0.2);
                setTimeout(function () {
                    if (jsb.fileUtils.isFileExist(fullPicName))
                    {
                        jsb.fileUtils.removeFile(fullPicName);
                    }
                },12000);
            } else if (cc.sys.os == cc.sys.OS_IOS) {
                $.OnJiePing(picName);

                var appUrl="http://a.app.qq.com/o/simple.jsp?pkgname=com.cjpoker.zujumj";
                var iconUrl="";
                this.scheduleOnce(function(){
                    jsb.reflection.callStaticMethod("RootViewController","OnSavePicWithName:shareType:shareContent:title:appUrl:text:iconUrl:",picName,"wechat","image","",appUrl,"",iconUrl);
                },0.2);
                setTimeout(function () {
                    if (jsb.fileUtils.isFileExist(picName))
                    {
                        jsb.fileUtils.removeFile(picName);
                    }
                },2000);
            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
    },
    OnClickTimeLinet : function()
    {
        try
        {
            var uid = dwc.Myself.GetData().GetUid();
            var now_time = new Date().getTime();
            var picName="" +now_time+".png";

            if (cc.sys.os == cc.sys.OS_ANDROID) {
                var fullPicName = jsb.fileUtils.getWritablePath() + "/" + picName;

                if (jsb.fileUtils.isFileExist(fullPicName))
                {
                    jsb.fileUtils.removeFile(fullPicName);
                }
                $.OnJiePing(picName);
                //setTimeout(function () {
                this.scheduleOnce(function(){
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "ShareToTimeLineLocImg", "(Ljava/lang/String;)V", fullPicName);
                },0.2);
                setTimeout(function () {
                    if (jsb.fileUtils.isFileExist(fullPicName))
                    {
                        jsb.fileUtils.removeFile(fullPicName);
                    }
                },12000);
                //},200);
            } else if (cc.sys.os == cc.sys.OS_IOS) {

                $.OnJiePing(picName);

                var appUrl="http://a.app.qq.com/o/simple.jsp?pkgname=com.cjpoker.zujumj";
                var iconUrl="";
                //setTimeout(function () {

                this.scheduleOnce(function(){
                    jsb.reflection.callStaticMethod("RootViewController","OnSavePicWithName:shareType:shareContent:title:appUrl:text:iconUrl:",picName,"pyq","image","",appUrl,"",iconUrl);
                },0.2);
                setTimeout(function () {
                    if (jsb.fileUtils.isFileExist(picName))
                    {
                        jsb.fileUtils.removeFile(picName);

                        /*
                        var msgAlert=new dwc.PopupAlert("文件找到了");
                        $.runningScene.addChild(msgAlert);
                        msgAlert.Show();
                        */
                    }
                },2000);

            }
        }catch (e)
        {
            cc.log(e.name + ":" + e.message);
        }
    }
});



var csmj_MJTest = function ()
{
    //清除胡牌数据
    this.CleanHu = function( hu )
    {
        hu.jiangMj = INVALID_CARD;
        for( var i=0; i<(HAND_MJ_MAX-2)/3; i++ )
        {
            hu.block[i].first = INVALID_CARD;
            hu.block[i].style = BLOCK_NULL;
        }
        return hu;
    };
//拷贝胡牌数据
    this.CopyHu = function( destHu, srcHu )
    {
        destHu.jiangMj = srcHu.jiangMj;
        for( var i=0; i<(HAND_MJ_MAX-2)/3; i++ )
        {
            destHu.block[i].first = srcHu.block[i].first;
            destHu.block[i].style = srcHu.block[i].style;
        }
        return destHu;
    };

    this.SortCard = function( byHandCard, byHandMjCount)
    {
        for(var  i = 0;i < byHandMjCount - 1;i++)
        {
            for(var  j = i;j < byHandMjCount;j++)
            {
                if(byHandCard[i] > byHandCard[j])
                {
                    var tempvalue = byHandCard[i];
                    byHandCard[i] = byHandCard[j];
                    byHandCard[j] = tempvalue;
                }
            }
        }
        return byHandCard;
    };

//加入块到胡牌结构
    this.AddBlock = function( hu,  block )
    {
        for( var i=0; i<(HAND_MJ_MAX-2)/3; i++ )
        {
            if( hu.block[i].style == BLOCK_NULL )
            {
                hu.block[i].first = block.first;
                hu.block[i].style = block.style;
                break;
            }
        }
        return hu;
    };

    //类型判断
    this.CheckBlock = function(  byMj1,  byMj2,  byMj3 )
    {
        var block = {};
        block.first = INVALID_CARD;
        block.style = BLOCK_NULL;
        if (this.IsTongHuaSe(byMj1,byMj2,byMj3) == false)
        {
            return block;
        }
        //如果byMj1, byMj2, byMj3不是顺序结构,排序
        var i, tag, temp;
        for( i=0,tag=1; tag==1&&i<3; i++ )
        {
            tag = 0;
            if( byMj1 > byMj2 )
            {
                temp = byMj1;
                byMj1 = byMj2;
                byMj2 = temp;
                tag = 1;
            }
            if( byMj2 > byMj3 )
            {
                temp = byMj2;
                byMj2 = byMj3;
                byMj3 = temp;
                tag = 1;
            }
        }

        //碰形结构
        if( byMj1==byMj2 && byMj2==byMj3 )
        {
            block.first = byMj1;
            block.style = BLOCK_KE;
            return block;
        }

        //顺形结构
        if( byMj3<27 )			//不为字, 花
        {
            if( byMj3==byMj2+1 && byMj2==byMj1+1 )
            {
                block.first = byMj1;
                block.style = BLOCK_SUN;
                return block;
            }
        }
        return block;
    };

    this.IsTongHuaSe = function(  byMj1,  byMj2, byMj3 )
    {
        if (byMj1>= 0 &&byMj1<=8  && byMj2>= 0 &&byMj2<=8  && byMj3>= 0 &&byMj3<=8)
        {
            return	true;
        }
        if (byMj1>= 9 &&byMj1<=17  && byMj2>= 9 &&byMj2<=17  && byMj3>= 9 &&byMj3<=17)
        {
            return	true;
        }
        if (byMj1>= 18 &&byMj1<=26  && byMj2>= 18 &&byMj2<=26  && byMj3>= 18 &&byMj3<=26)
        {
            return	true;
        }
        if((byMj1 == byMj2)  && (byMj2 == byMj3) && (byMj1 < 42))
        {
            return	true;
        }
        return	false;
    };
    //是否可以做将牌
    this.IsJiang = function(  byMj1,  byMj2 )
    {
        if( byMj1 == byMj2 &&  (byMj1 < 42))
        {
            return true;
        }
        return false;
    };
//////////////////////////////////////////////////////////////////////////
//	0-8		一万-九万
//	9-17	一条-九条w
//	18-26	一筒-九筒
//	27-33	东南西北中发白
//	34-41	春夏秋冬梅兰竹菊
//////////////////////////////////////////////////////////////////////////
    this.IsHu = function( byHandMj,  byMj,  hu,  tempHu)
    {
        var cntBlock = 0;
        //排序牌面
        var OriginalMj=byHandMj;
        for( var i=0; i<HAND_MJ_MAX-1; i++ )
        {
            OriginalMj[i] = byHandMj[i];
        }
        if (byMj != INVALID_CARD)
        {
            OriginalMj[HAND_MJ_MAX-1] = byMj;
        }

        var cntMaxBlock = 0;
        var cntValidPai = 0;
        for( var i=0; i<HAND_MJ_MAX; i++ )
        {
            if(OriginalMj[i] < 42)
            {
                cntValidPai++;
            }
        }
        cntMaxBlock = parseInt(cntValidPai / 3);
        OriginalMj = this.SortCard(OriginalMj,HAND_MJ_MAX);

        //将牌位在整数块( 0, 3, 6, 9, 12, 15 )处
        //设置变量
        var block1;
        for( var i=0; i<HAND_MJ_MAX-1; i++ )
        {
            cntBlock = 0;
            var tempMj=[];
            for( var k=0; k<HAND_MJ_MAX; k++ )
            {
                tempMj[k] = OriginalMj[k];
            }
            if( this.IsJiang( tempMj[i], tempMj[i+1] ) )
            {
                //胡牌结构处理
                this.CleanHu( tempHu );
                this.CopyHu( tempHu, hu );
                tempHu.jiangMj = tempMj[i];
                tempMj[i]	=	INVALID_CARD;
                tempMj[i+1]	=	INVALID_CARD;
                tempMj = this.SortCard(tempMj,HAND_MJ_MAX);
                //单钓
                if( cntBlock == cntMaxBlock)
                {
                    return true;
                }
                for( var j=0; j<HAND_MJ_MAX-2; j+=3 )
                {
                    block1 = this.CheckBlock( tempMj[j], tempMj[j+1], tempMj[j+2] );
                    if( block1.style != BLOCK_NULL )
                    {
                        tempHu = this.AddBlock( tempHu, block1 );
                        cntBlock++;
                    }
                    else
                    {
                        //有相嵌的两个BLOCK结构,或三个BLOCK结构
                        if( j+5<=HAND_MJ_MAX-1)
                        {
                            var block2;
                            //两种情况  223344 或 233334 或 233444556 或 233344455 或 334445556
                            //情况1   223344 233445
                            block1 = this.CheckBlock( tempMj[j], tempMj[j+2], tempMj[j+4] );
                            block2 = this.CheckBlock( tempMj[j+1], tempMj[j+3], tempMj[j+5] );
                            if( block1.style != BLOCK_NULL  && block2.style != BLOCK_NULL )
                            {
                                j += 3;
                                cntBlock++;
                                cntBlock++;
                            }
                            //情况2 233334
                            else
                            {
                                block1 = this.CheckBlock( tempMj[j], tempMj[j+1], tempMj[j+5] );
                                block2 = this.CheckBlock( tempMj[j+2], tempMj[j+3], tempMj[j+4] );
                                if( block1.style != BLOCK_NULL && block2.style != BLOCK_NULL )
                                {
                                    j += 3;
                                    cntBlock++;
                                    cntBlock++;
                                }
                                //情况3 233444556
                                else
                                {
                                    if (j+8<=HAND_MJ_MAX-1)
                                    {
                                        var block3;
                                        block1 = this.CheckBlock( tempMj[j], tempMj[j+1], tempMj[j+3] );
                                        block2 = this.CheckBlock( tempMj[j+2], tempMj[j+4], tempMj[j+6] );
                                        block3 = this.CheckBlock( tempMj[j+5], tempMj[j+7], tempMj[j+8] );
                                        if( block1.style != BLOCK_NULL && block2.style != BLOCK_NULL && block3.style != BLOCK_NULL)
                                        {
                                            j += 6;
                                            cntBlock++;
                                            cntBlock++;
                                            cntBlock++;
                                        }
                                        //情况3 334445556
                                        else
                                        {
                                            var block3;
                                            block1 = this.CheckBlock( tempMj[j], tempMj[j+1], tempMj[j+4] );
                                            block2 = this.CheckBlock( tempMj[j+2], tempMj[j+5], tempMj[j+7] );
                                            block3 = this.CheckBlock( tempMj[j+3], tempMj[j+6], tempMj[j+8] );
                                            if (block1.style != BLOCK_NULL && block2.style != BLOCK_NULL && block3.style != BLOCK_NULL)
                                            {
                                                j += 6;
                                                cntBlock++;
                                                cntBlock++;
                                                cntBlock++;
                                            }else
                                            {
                                                block1 = this.CheckBlock( tempMj[j], tempMj[j+2], tempMj[j+5] );
                                                block2 = this.CheckBlock( tempMj[j+1], tempMj[j+3], tempMj[j+6] );
                                                block3 = this.CheckBlock( tempMj[j+4], tempMj[j+7], tempMj[j+8] );
                                                if( block1.style != BLOCK_NULL && block2.style != BLOCK_NULL && block3.style != BLOCK_NULL)
                                                {
                                                    j += 6;
                                                    cntBlock++;
                                                    cntBlock++;
                                                    cntBlock++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }
                        else
                        {
                            break;
                        }
                    }
                    if( cntBlock == cntMaxBlock)
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    };

    this.GetTingXuan = function (byHandMj,block) {
        var hus = [];
        var tingxuan = [];
        var MJTestObj = new csmj_MJTest();

        for (var i = 0 ; i < 14; i ++){//排除第i张牌 看能胡牌不
            //hus.push([]);

            if(byHandMj[i] < 42)
            {
                var test_handMj = FZArray(byHandMj);
                test_handMj.splice(i,1);//排除第i张牌

                    for (var byMj = 0; byMj <= 41;byMj++){
                        var temp_handMj = FZArray(byHandMj);
                        temp_handMj.splice(i,1);//排除第i张牌
                        var hu = new HU();
                        var tempHu = new HU();
                        var isHu = MJTestObj.IsHu(temp_handMj,byMj,hu,tempHu);
                        if (isHu){
                            if(hus.indexOf(byMj) < 0)
                            {
                                hus.push(byMj);
                            }
                            if(tingxuan.indexOf(byHandMj[i]) < 0)
                            {
                                tingxuan.push(byHandMj[i]);
                            }
                            break;
                        }
                    }

            }

            console.log("");
        }
        //console.log(JSON.stringify(hus));
        return tingxuan;
    }

    this.GetKeHuPai = function (byHandMj) {
        var hus = [];
        var tingxuan = [];
        var MJTestObj = new csmj_MJTest();


        for (var byMj = 0; byMj <= 26;byMj++){
            var temp_handMj = FZArray(byHandMj);
            var hu = new HU();
            var tempHu = new HU();
            var isHu = MJTestObj.IsHu(temp_handMj,byMj,hu,tempHu);
            if (isHu){
                if(hus.indexOf(byMj) < 0)
                {
                    hus.push(byMj);
                }
            }
        }
        return hus;
    }
};

